﻿using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Resources;

using CE.User;
using CE.Global;
using CE.Database;
using CE.Report;

public partial class telereport_agent_sales_summary : System.Web.UI.Page
{
    string PageCode = "GGRPTTMAGSALE";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("~/ManagementSecureLogin.aspx");
        }

        if (!IsPostBack)
        {
            if (Convert.ToInt64(Session[General.UserId].ToString()) != 1)
            {
                CheckPageAccess();
            }
            if (Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() == "200")
            {
                hplBacktoMenu.Visible = true;
            }
            else
            {
                hplBacktoMenu.Visible = false;
            }

            if (Convert.ToInt64(Session[General.UserId].ToString()) == 14)
            {
                ddlSeller.Text = "1";
                ddlSeller.Enabled = false;
            }
            else
            {
                ddlSeller.Enabled = true;
            }

            lblError.Text = "";
            lblContent.Text = "";
            ddlDay1.Visible = true;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
            ddlYear1.Items.Clear();
            ddlYear2.Items.Clear();

            int _cryr = CE.Global.General.GetUTCDateTime().Year;
            int _styr = 2010;
            for (int _year = _cryr; _year >= _styr; _year--)
            {
                ddlYear1.Items.Add(new ListItem(_year.ToString(), _year.ToString()));
                ddlYear2.Items.Add(new ListItem(_year.ToString(), _year.ToString()));
            }

            ddlDay1.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
            ddlMonth1.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
            ddlYear1.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
            ddlDay2.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
            ddlMonth2.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
            ddlYear2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
            LoadInsurerList();
            ddlReportType_SelectedIndexChanged(null, null);
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        lblError.Text = "";
        txtReportType.Text = ddlReportType.Text;
        LoadGrid();
    }

    protected void btnDownLoad_Click(object sender, EventArgs e)
    {
        GenerateExcel();
    }

    protected void btnDownloadOIC_Click(object sender, EventArgs e)
    {
        GenerateOICExcel();
    }

    protected void ddlReportType_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblError.Text = "";
        ddlDay1.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
        ddlDay2.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
        ddlMonth1.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
        ddlMonth2.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
        ddlYear1.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
        ddlYear2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
        if (Convert.ToInt16(ddlReportType.Text) == 0)
        {
            ddlDay1.Visible = false;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 1)
        {
            ddlDay1.Visible = true;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 2)
        {
            lblFromDate.Text = "From Date :";
            lblToDate.Text = " To Date :";
            lblToDate.Visible = true;
            ddlDay2.Visible = true;
            ddlMonth2.Visible = true;
            ddlYear2.Visible = true;
            ddlDay1.Visible = true;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 3)
        {
            ddlDay1.Visible = false;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 4)
        {
            ddlDay1.Visible = false;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
    }

    protected void grvSalesSummary_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            //e.Row.Cells[6].Attributes.CssStyle.Add("text-align", "right");
            //e.Row.Cells[7].Attributes.CssStyle.Add("text-align", "right");
            e.Row.Cells[8].Attributes.CssStyle.Add("text-align", "right");
            e.Row.Cells[9].Attributes.CssStyle.Add("text-align", "right");
            e.Row.Cells[10].Attributes.CssStyle.Add("text-align", "right");
            e.Row.Cells[11].Attributes.CssStyle.Add("text-align", "right");
            if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
            {
                e.Row.Cells[4].Visible = true;
            }
            else
            {
                e.Row.Cells[4].Visible = false;
            }
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //e.Row.Cells[6].Attributes.CssStyle.Add("text-align", "right");
            //e.Row.Cells[7].Attributes.CssStyle.Add("text-align", "right");
            e.Row.Cells[8].Attributes.CssStyle.Add("text-align", "right");
            e.Row.Cells[9].Attributes.CssStyle.Add("text-align", "right");
            e.Row.Cells[10].Attributes.CssStyle.Add("text-align", "right");
            e.Row.Cells[11].Attributes.CssStyle.Add("text-align", "right");
            if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
            {
                e.Row.Cells[4].Visible = true;
            }
            else
            {
                e.Row.Cells[4].Visible = false;
            }
        }
    }

    public bool ValidDate(Int32 Year, Int32 Month, Int32 Day)
    {
        bool _isValid = true;
        int daysInMonth = 0;
        string leap, monthValid, dayValid, yearValid;
        if (Year >= 0000)
        {
            yearValid = "yes";
        }
        else
        {
            yearValid = "no";
        }
        if (Year % 400 == 0)
        {
            leap = "yes";
        }
        else if (Year % 100 == 0)
        {
            leap = "no";
        }
        else if (Year % 4 == 0)
        {
            leap = "yes";
        }
        else
        {
            leap = "no";
        }

        switch (Month)
        {
            case 1: daysInMonth = 31;
                break;
            case 3: daysInMonth = 31;
                break;
            case 4: daysInMonth = 30;
                break;
            case 5: daysInMonth = 31;
                break;
            case 6: daysInMonth = 30;
                break;
            case 7: daysInMonth = 31;
                break;
            case 8: daysInMonth = 31;
                break;
            case 9: daysInMonth = 30;
                break;
            case 10: daysInMonth = 31;
                break;
            case 11: daysInMonth = 30;
                break;
            case 12: daysInMonth = 31;
                break;
        }

        if (Month >= 1 && Month <= 12)
        {
            monthValid = "yes";
        }
        else
        {
            monthValid = "no";
        }
        if (Month == 2)
        {
            if (leap == "no")
            {
                daysInMonth = 28;
            }
            else if (leap == "yes")
            {
                daysInMonth = 29;
            }
        }

        if (1 <= Day && Day <= daysInMonth)
        {
            dayValid = "yes";
        }

        else
        {
            dayValid = "no";
        }

        if ((dayValid == "yes") && (monthValid == "yes") && (yearValid == "yes"))
        {
            _isValid = true;
        }
        else
        {
            _isValid = false;
        }

        return _isValid;
    }

    public string GetMonth(string month)
    {
        string result = "";
        if (month == "01")
        {
            result = " Jan ";
        }
        else if (month == "02")
        {
            result = " Feb ";
        }
        else if (month == "03")
        {
            result = " Mar ";
        }
        else if (month == "04")
        {
            result = " Apr ";
        }
        else if (month == "05")
        {
            result = " May ";
        }
        else if (month == "06")
        {
            result = " Jun ";
        }
        else if (month == "07")
        {
            result = " Jul ";
        }
        else if (month == "08")
        {
            result = " Aug ";
        }
        else if (month == "09")
        {
            result = " Sep ";
        }
        else if (month == "10")
        {
            result = " Oct ";
        }
        else if (month == "11")
        {
            result = " Nov ";
        }
        else if (month == "12")
        {
            result = " Dec ";
        }
        return result;
    }

    public string LastDayOfMonth(string ReportDate)
    {
        string result = "31";
        DateTime dtReportDate = Convert.ToDateTime(ReportDate);
        DateTime today = dtReportDate;
        DateTime endOfMonth = new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month));
        result = endOfMonth.Day.ToString("00");
        return result;
    }

    public bool Validatioin()
    {
        lblError.Text = "";
        bool _isValid = true;
        DateTime _fromDate, _toDate;
        if (Convert.ToInt16(ddlReportType.Text) == 1)
        {
            if (ddlDay1.SelectedIndex >= 0)
            {
                if (ValidDate(Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlDay1.Text)))
                {
                    _fromDate = Convert.ToDateTime(Convert.ToInt32(ddlYear1.Text) + "/" + Convert.ToInt32(ddlMonth1.Text) + "/" + Convert.ToInt32(ddlDay1.Text));
                    if (_fromDate > CE.Global.General.GetUTCDateTime())
                    {
                        _isValid = false;
                        lblError.Text = "Date should be less than or equal to Today";
                    }
                }
                else
                {
                    _isValid = false;
                    lblError.Text = "Select Valid Date";
                }
            }
            else
            {
                _isValid = false;
                lblError.Text = "Select Date";
            }
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 2)
        {
            if (ddlDay1.SelectedIndex >= 0 && ddlDay2.SelectedIndex >= 0)
            {
                if (ValidDate(Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlDay1.Text)))
                {
                    _fromDate = Convert.ToDateTime(Convert.ToInt32(ddlYear1.Text) + "/" + Convert.ToInt32(ddlMonth1.Text) + "/" + Convert.ToInt32(ddlDay1.Text));
                    if (ValidDate(Convert.ToInt32(ddlYear2.Text), Convert.ToInt32(ddlMonth2.Text), Convert.ToInt32(ddlDay2.Text)))
                    {
                        _toDate = Convert.ToDateTime(Convert.ToInt32(ddlYear2.Text) + "/" + Convert.ToInt32(ddlMonth2.Text) + "/" + Convert.ToInt32(ddlDay2.Text));
                        if (_fromDate <= CE.Global.General.GetUTCDateTime())
                        {
                            if (_fromDate > _toDate)
                            {
                                _isValid = false;
                                lblError.Text = "From date should be less than To date";
                            }
                        }
                        else
                        {
                            _isValid = false;
                            lblError.Text = "From date should be less than Today";
                        }
                    }
                    else
                    {
                        _isValid = false;
                        lblError.Text = "Select Valid To date";
                    }
                }
                else
                {
                    _isValid = false;
                    lblError.Text = "Select Valid From date";
                }
            }
            else
            {
                _isValid = false;
                lblError.Text = "Select From date and To date";
            }
        }
        return _isValid;
    }

    public void LoadGrid()
    {
        lblError.Text = "";
        if (Validatioin() == true)
        {
            txtReportDate1.Text = "";
            txtReportDate2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000") + CE.Global.General.GetUTCDateTime().Month.ToString("00") + CE.Global.General.GetUTCDateTime().Day.ToString("00");
            txtReportDate1.Text = ddlYear1.Text;
            txtReportDate1.Text += ddlMonth1.Text;
            txtReportDate1.Text += ddlDay1.Text;
            if (Convert.ToInt16(ddlReportType.Text) == 0)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 1)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += ddlDay1.Text;
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 2)
            {
                txtReportDate2.Text = ddlYear2.Text;
                txtReportDate2.Text += ddlMonth2.Text;
                txtReportDate2.Text += ddlDay2.Text;
            }
            if (Convert.ToInt16(ddlReportType.Text) == 3)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += "01";
            }
            if (Convert.ToInt16(ddlReportType.Text) == 4)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += "16";
            }
            DataSet _dsSummary = new DataSet();
            DataTable _dtSummary = new DataTable();
            Int16 _ReportType = Convert.ToInt16(ddlReportType.Text);
            string _ReportDate1 = txtReportDate1.Text.Trim();
            string _ReportDate2 = txtReportDate2.Text.Trim();
            if (_ReportDate1.Length == 6)
            {
                txtReportDate.Text = _ReportDate1.ToString() + "01";
            }
            else if (_ReportDate1.Length == 8)
            {
                txtReportDate.Text = _ReportDate1.ToString();
            }
            Int32 _UserTypeId = Convert.ToInt32(ddlCampaign.Text);

            MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
            string _spName = "[sprocCXCRMAgentSalesSummarySelectedList]";
            SortedList _sPara = new SortedList();

            _sPara.Add("@ReportType", _ReportType);
            _sPara.Add("@ReportDate1", _ReportDate1);
            _sPara.Add("@ReportDate2", _ReportDate2);
            _sPara.Add("@Insurer", Convert.ToInt64(ddlProvider.Text));
            if (Convert.ToInt64(Session[General.UserId].ToString()) == 14)
            {
                _sPara.Add("@IsAgentOnly", 1);
            }
            else
            {
                _sPara.Add("@IsAgentOnly", Convert.ToInt16(ddlSeller.Text));
            }
            _sPara.Add("@UserTypeId", _UserTypeId);

            _dsSummary = _db.GetDataSet(_spName, _sPara);
            if (_dsSummary != null && _dsSummary.Tables.Count > 0 && _dsSummary.Tables[0].Rows.Count > 0)
            {
                _dtSummary = _dsSummary.Tables[0];
                grvSalesSummary.DataSource = _dtSummary;
                grvSalesSummary.DataBind();
                EnablePrintView();
            }
            else
            {
                grvSalesSummary.DataSource = null;
                grvSalesSummary.DataBind();
                EnablePrintView();
            }
        }
        else
        {
            grvSalesSummary.DataSource = null;
            grvSalesSummary.DataBind();
            EnablePrintView();
        }
    }

    private void EnablePrintView()
    {
        if (grvSalesSummary.Rows.Count > 0)
        {
            ddlLanguage.Visible = true;
            btnDownLoad.Visible = true;
            btnDownloadOIC.Visible = false;
            lblRecordCount.Text = "(" + grvSalesSummary.Rows.Count.ToString() + ") record(s). Date/Time: " + CE.Global.General.GetUTCDateTime().ToString("dd-MMM-yyyy hh:mm tt") + "&nbsp;&nbsp;";
        }
        else
        {
            //ddlLanguage.Visible = false;
            btnDownLoad.Visible = false;
            btnDownloadOIC.Visible = false;
            //lblRecordCount.Text = "No record found. Date/Time: " + CE.Global.General.GetUTCDateTime().ToString("dd-MMM-yyyy hh:mm tt") + "&nbsp;&nbsp;";
            lblRecordCount.Text = "";
        }
    }

    public void GenerateExcelOld()
    {
        string _html = "";
        string _fileName = "AgentSales@" + CE.Global.General.GetUTCDateTime().Day.ToString("00") + "-" + CE.Global.General.GetUTCDateTime().Month.ToString("00") + "-" + CE.Global.General.GetUTCDateTime().Year;
        lblContent.Text = "";
        lblError.Text = "";
        if (Validatioin() == true)
        {
            txtReportDate1.Text = "";
            txtReportDate2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000") + CE.Global.General.GetUTCDateTime().Month.ToString("00") + CE.Global.General.GetUTCDateTime().Day.ToString("00");
            txtReportDate1.Text = ddlYear1.Text;
            txtReportDate1.Text += ddlMonth1.Text;
            txtReportDate1.Text += ddlDay1.Text;
            if (Convert.ToInt16(ddlReportType.Text) == 0)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;                
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 1)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += ddlDay1.Text;
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 2)
            {
                txtReportDate2.Text = ddlYear2.Text;
                txtReportDate2.Text += ddlMonth2.Text;
                txtReportDate2.Text += ddlDay2.Text;
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 3)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += "01";
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 4)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += "16";
            }


            Int32 OnlineCount = 0;
            Int32 OfflineCount = 0;
            Int32 TotalFileCount = 0;
            DataSet _dsSummary = new DataSet();
            DataTable _dtSummary = new DataTable();
            Int16 _ReportType = Convert.ToInt16(ddlReportType.Text);
            string _ReportDate1 = txtReportDate1.Text.Trim();
            string _ReportDate2 = txtReportDate2.Text.Trim();
            Int32 _UserTypeId = Convert.ToInt32(ddlCampaign.Text);

            MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
            string _spName = "[sprocCXCRMAgentSalesSummarySelectedList]";
            SortedList _sPara = new SortedList();

            _sPara.Add("@ReportType", _ReportType);
            _sPara.Add("@ReportDate1", _ReportDate1);
            _sPara.Add("@ReportDate2", _ReportDate2);
            _sPara.Add("@Insurer", Convert.ToInt64(ddlProvider.Text));
            if (Convert.ToInt64(Session[General.UserId].ToString()) == 14)
            {
                _sPara.Add("@IsAgentOnly", 1);
            }
            else
            {
                _sPara.Add("@IsAgentOnly", Convert.ToInt16(ddlSeller.Text));
            }
            _sPara.Add("@UserTypeId", _UserTypeId);

            _dsSummary = _db.GetDataSet(_spName, _sPara);
            if (_dsSummary != null && _dsSummary.Tables.Count > 0 && _dsSummary.Tables[0].Rows.Count > 0)
            {
                _dtSummary = _dsSummary.Tables[0];
                TotalFileCount += _dtSummary.Rows.Count;
            }
            if (TotalFileCount > 0)
            {
                #region Variable Declaration
                string PaymentType = "";
                string[] QuoteRefNo = new string[TotalFileCount];
                string[] CECarId = new string[TotalFileCount];
                string[] ProviderCompanyId = new string[TotalFileCount];
                string[] OrderDate = new string[TotalFileCount];
                string[] CustomerType = new string[TotalFileCount];
                string[] ApplicationName = new string[TotalFileCount];
                string[] Insurer = new string[TotalFileCount];
                string[] InsuranceType = new string[TotalFileCount];
                string[] InsuranceTypeId = new string[TotalFileCount];
                string[] PolicyStartDate = new string[TotalFileCount];
                string[] PolicyEndDate = new string[TotalFileCount];
                string[] SalesPremium = new string[TotalFileCount];
                string[] GrossPremium = new string[TotalFileCount];
                string[] NetPremium = new string[TotalFileCount];
                string[] Duty = new string[TotalFileCount];
                string[] VAT = new string[TotalFileCount];
                string[] CPolicyStartDate = new string[TotalFileCount];
                string[] CPolicyEndDate = new string[TotalFileCount];
                string[] CNetPremium = new string[TotalFileCount];
                string[] CDuty = new string[TotalFileCount];
                string[] CVAT = new string[TotalFileCount];
                string[] CGrossPremium = new string[TotalFileCount];
                string[] CollectedPremium = new string[TotalFileCount];
                string[] DiscounttoCustomer = new string[TotalFileCount];
                string[] Discount = new string[TotalFileCount];
                string[] Agent = new string[TotalFileCount];
                string[] Remark = new string[TotalFileCount];
                string[] PremiumReceivingDate = new string[TotalFileCount];
                string[] Bank = new string[TotalFileCount];
                string[] MethodofPayment = new string[TotalFileCount];
                string[] BBLBankCharge = new string[TotalFileCount];
                string[] VAT7 = new string[TotalFileCount];
                string[] BBLNetReceived = new string[TotalFileCount];
                string[] Difference = new string[TotalFileCount];
                string[] IsCTPL = new string[TotalFileCount];
                string[] CTPL = new string[TotalFileCount];
                string[] GarageType = new string[TotalFileCount];

                string[] OICInsurer = new string[15];
                string[] OICVoluntary = new string[15];
                string[] OICCompulsory = new string[15];
                string[] OICTotal = new string[15];

                string[] IntInsurer = new string[15];
                string[] IntVoluntary = new string[15];
                string[] IntCompulsory = new string[15];
                string[] IntTotal = new string[15];

                string[] MktInsurer = new string[15];
                string[] MktVoluntary = new string[15];
                string[] MktCompulsory = new string[15];
                string[] MktTotal = new string[15];

                int int_PayCount, int_CCCount;
                float fl_SalePremium;
                string str_NetPremium, str_GrossPremium, str_VAT, str_Duty, str_CNetPremium, str_CGrossPremium, str_CVAT, str_CDuty, str_DiscountToCustomer;
                string TotalNetPremium, TotalCNetPremium, TotalCollectedPremium, TotalBBLBankCharge, TotalVAT7, TotalBBLNetReceived, TotalDifference;
                string OICVoluntaryTotal, OICCompulsoryTotal, OICFinalTotal, IntVoluntaryTotal, IntCompulsoryTotal, IntFinalTotal;
                string MktVoluntaryTotal, MktCompulsoryTotal, MktFinalTotal;
                string C_OICAZCP, C_OICAXA, C_OICBKI, C_OICCTS, C_OICKUR, C_OICLMG, C_OICMSIG, C_OICMTI, C_OICTMS, C_OICKPI, C_OICMIR, C_OICSMK, C_OICVRY, C_OICTVV, C_OICSCS;
                string C_IntAZCP, C_IntAXA, C_IntBKI, C_IntCTS, C_IntKUR, C_IntLMG, C_IntMSIG, C_IntMTI, C_IntTMS, C_IntKPI, C_IntMIR, C_IntSMK, C_IntVRY, C_IntTVV, C_IntSCS;
                string C_MktAZCP, C_MktAXA, C_MktBKI, C_MktCTS, C_MktKUR, C_MktLMG, C_MktMSIG, C_MktMTI, C_MktTMS, C_MktKPI, C_MktMIR, C_MktSMK, C_MktVRY, C_MktTVV, C_MktSCS;

                string V_OICAZCP, V_OICAXA, V_OICBKI, V_OICCTS, V_OICKUR, V_OICLMG, V_OICMSIG, V_OICMTI, V_OICTMS, V_OICKPI, V_OICMIR, V_OICSMK, V_OICVRY, V_OICTVV, V_OICSCS;
                string V_IntAZCP, V_IntAXA, V_IntBKI, V_IntCTS, V_IntKUR, V_IntLMG, V_IntMSIG, V_IntMTI, V_IntTMS, V_IntKPI, V_IntMIR, V_IntSMK, V_IntVRY, V_IntTVV, V_IntSCS;
                string V_MktAZCP, V_MktAXA, V_MktBKI, V_MktCTS, V_MktKUR, V_MktLMG, V_MktMSIG, V_MktMTI, V_MktTMS, V_MktKPI, V_MktMIR, V_MktSMK, V_MktVRY, V_MktTVV, V_MktSCS;

                string Total_OICAZCP, Total_OICAXA, Total_OICBKI, Total_OICCTS, Total_OICKUR, Total_OICLMG, Total_OICMSIG, Total_OICMTI, Total_OICTMS, Total_OICKPI, Total_OICMIR, Total_OICSMK, Total_OICVRY, Total_OICTVV, Total_OICSCS;
                string Total_IntAZCP, Total_IntAXA, Total_IntBKI, Total_IntCTS, Total_IntKUR, Total_IntLMG, Total_IntMSIG, Total_IntMTI, Total_IntTMS, Total_IntKPI, Total_IntMIR, Total_IntSMK, Total_IntVRY, Total_IntTVV, Total_IntSCS;
                string Total_MktAZCP, Total_MktAXA, Total_MktBKI, Total_MktCTS, Total_MktKUR, Total_MktLMG, Total_MktMSIG, Total_MktMTI, Total_MktTMS, Total_MktKPI, Total_MktMIR, Total_MktSMK, Total_MktVRY, Total_MktTVV, Total_MktSCS;

                TotalNetPremium = "0"; TotalCNetPremium = "0"; TotalCollectedPremium = "0"; TotalBBLBankCharge = "0"; TotalVAT7 = "0"; TotalBBLNetReceived = "0"; TotalDifference = "0";
                OICVoluntaryTotal = "0"; OICCompulsoryTotal = "0"; OICFinalTotal = "0"; IntVoluntaryTotal = "0"; IntCompulsoryTotal = "0"; IntFinalTotal = "0";
                MktVoluntaryTotal = "0"; MktCompulsoryTotal = "0"; MktFinalTotal = "0";
                C_OICAZCP = "0"; C_OICAXA = "0"; C_OICBKI = "0"; C_OICCTS = "0"; C_OICKUR = "0"; C_OICLMG = "0"; C_OICMSIG = "0"; C_OICMTI = "0"; C_OICTMS = "0"; C_OICKPI = "0"; C_OICMIR = "0"; C_OICSMK = "0"; C_OICVRY = "0"; C_OICTVV = "0"; C_OICSCS = "0";
                C_IntAZCP = "0"; C_IntAXA = "0"; C_IntBKI = "0"; C_IntCTS = "0"; C_IntKUR = "0"; C_IntLMG = "0"; C_IntMSIG = "0"; C_IntMTI = "0"; C_IntTMS = "0"; C_IntKPI = "0"; C_IntMIR = "0"; C_IntSMK = "0"; C_IntVRY = "0"; C_IntTVV = "0"; C_IntSCS = "0";
                C_MktAZCP = "0"; C_MktAXA = "0"; C_MktBKI = "0"; C_MktCTS = "0"; C_MktKUR = "0"; C_MktLMG = "0"; C_MktMSIG = "0"; C_MktMTI = "0"; C_MktTMS = "0"; C_MktKPI = "0"; C_MktMIR = "0"; C_MktSMK = "0"; C_MktVRY = "0"; C_MktTVV = "0"; C_MktSCS = "0";

                V_OICAZCP = "0"; V_OICAXA = "0"; V_OICBKI = "0"; V_OICCTS = "0"; V_OICKUR = "0"; V_OICLMG = "0"; V_OICMSIG = "0"; V_OICMTI = "0"; V_OICTMS = "0"; V_OICKPI = "0"; V_OICMIR = "0"; V_OICSMK = "0"; V_OICVRY = "0"; V_OICTVV = "0"; V_OICSCS = "0";
                V_IntAZCP = "0"; V_IntAXA = "0"; V_IntBKI = "0"; V_IntCTS = "0"; V_IntKUR = "0"; V_IntLMG = "0"; V_IntMSIG = "0"; V_IntMTI = "0"; V_IntTMS = "0"; V_IntKPI = "0"; V_IntMIR = "0"; V_IntSMK = "0"; V_IntVRY = "0"; V_IntTVV = "0"; V_IntSCS = "0";
                V_MktAZCP = "0"; V_MktAXA = "0"; V_MktBKI = "0"; V_MktCTS = "0"; V_MktKUR = "0"; V_MktLMG = "0"; V_MktMSIG = "0"; V_MktMTI = "0"; V_MktTMS = "0"; V_MktKPI = "0"; V_MktMIR = "0"; V_MktSMK = "0"; V_MktVRY = "0"; V_MktTVV = "0"; V_MktSCS = "0";

                Total_OICAZCP = "0"; Total_OICAXA = "0"; Total_OICBKI = "0"; Total_OICCTS = "0"; Total_OICKUR = "0"; Total_OICLMG = "0"; Total_OICMSIG = "0"; Total_OICMTI = "0"; Total_OICTMS = "0"; Total_OICKPI = "0"; Total_OICMIR = "0"; Total_OICSMK = "0"; Total_OICVRY = "0"; Total_OICTVV = "0"; Total_OICSCS = "0";
                Total_IntAZCP = "0"; Total_IntAXA = "0"; Total_IntBKI = "0"; Total_IntCTS = "0"; Total_IntKUR = "0"; Total_IntLMG = "0"; Total_IntMSIG = "0"; Total_IntMTI = "0"; Total_IntTMS = "0"; Total_IntKPI = "0"; Total_IntMIR = "0"; Total_IntSMK = "0"; Total_IntVRY = "0"; Total_IntTVV = "0"; Total_IntSCS = "0";
                Total_MktAZCP = "0"; Total_MktAXA = "0"; Total_MktBKI = "0"; Total_MktCTS = "0"; Total_MktKUR = "0"; Total_MktLMG = "0"; Total_MktMSIG = "0"; Total_MktMTI = "0"; Total_MktTMS = "0"; Total_MktKPI = "0"; Total_MktMIR = "0"; Total_MktSMK = "0"; Total_MktVRY = "0"; Total_MktTVV = "0"; Total_MktSCS = "0";
                #endregion

                #region Default Value for OIC & Internal Reports
                //OIC
                OICInsurer[0] = GetProvider(16);
                OICInsurer[1] = GetProvider(11);
                OICInsurer[2] = GetProvider(32);
                OICInsurer[3] = GetProvider(31);
                OICInsurer[4] = GetProvider(35);
                OICInsurer[5] = GetProvider(41);
                OICInsurer[6] = GetProvider(29);
                OICInsurer[7] = GetProvider(12);
                OICInsurer[8] = GetProvider(33);
                OICInsurer[9] = GetProvider(46);
                OICInsurer[10] = GetProvider(39);
                OICInsurer[11] = GetProvider(43);
                OICInsurer[12] = GetProvider(45);
                OICInsurer[13] = GetProvider(58);
                OICInsurer[14] = GetProvider(50);

                OICVoluntary[0] = "0";
                OICVoluntary[1] = "0";
                OICVoluntary[2] = "0";
                OICVoluntary[3] = "0";
                OICVoluntary[4] = "0";
                OICVoluntary[5] = "0";
                OICVoluntary[6] = "0";
                OICVoluntary[7] = "0";
                OICVoluntary[8] = "0";
                OICVoluntary[9] = "0";
                OICVoluntary[10] = "0";
                OICVoluntary[11] = "0";
                OICVoluntary[12] = "0";
                OICVoluntary[13] = "0";
                OICVoluntary[14] = "0";

                OICCompulsory[0] = "0";
                OICCompulsory[1] = "0";
                OICCompulsory[2] = "0";
                OICCompulsory[3] = "0";
                OICCompulsory[4] = "0";
                OICCompulsory[5] = "0";
                OICCompulsory[6] = "0";
                OICCompulsory[7] = "0";
                OICCompulsory[8] = "0";
                OICCompulsory[9] = "0";
                OICCompulsory[10] = "0";
                OICCompulsory[11] = "0";
                OICCompulsory[12] = "0";
                OICCompulsory[13] = "0";
                OICCompulsory[14] = "0";

                OICTotal[0] = "0";
                OICTotal[1] = "0";
                OICTotal[2] = "0";
                OICTotal[3] = "0";
                OICTotal[4] = "0";
                OICTotal[5] = "0";
                OICTotal[6] = "0";
                OICTotal[7] = "0";
                OICTotal[8] = "0";
                OICTotal[9] = "0";
                OICTotal[10] = "0";
                OICTotal[11] = "0";
                OICTotal[12] = "0";
                OICTotal[13] = "0";
                OICTotal[14] = "0";

                //Internal
                IntInsurer[0] = GetProvider(16);
                IntInsurer[1] = GetProvider(11);
                IntInsurer[2] = GetProvider(32);
                IntInsurer[3] = GetProvider(31);
                IntInsurer[4] = GetProvider(35);
                IntInsurer[5] = GetProvider(41);
                IntInsurer[6] = GetProvider(29);
                IntInsurer[7] = GetProvider(12);
                IntInsurer[8] = GetProvider(33);
                IntInsurer[9] = GetProvider(46);
                IntInsurer[10] = GetProvider(39);
                IntInsurer[11] = GetProvider(43);
                IntInsurer[12] = GetProvider(45);
                IntInsurer[13] = GetProvider(58);
                IntInsurer[14] = GetProvider(50);

                IntVoluntary[0] = "0";
                IntVoluntary[1] = "0";
                IntVoluntary[2] = "0";
                IntVoluntary[3] = "0";
                IntVoluntary[4] = "0";
                IntVoluntary[5] = "0";
                IntVoluntary[6] = "0";
                IntVoluntary[7] = "0";
                IntVoluntary[8] = "0";
                IntVoluntary[9] = "0";
                IntVoluntary[10] = "0";
                IntVoluntary[11] = "0";
                IntVoluntary[12] = "0";
                IntVoluntary[13] = "0";
                IntVoluntary[13] = "0";
                IntVoluntary[14] = "0";

                IntCompulsory[0] = "0";
                IntCompulsory[1] = "0";
                IntCompulsory[2] = "0";
                IntCompulsory[3] = "0";
                IntCompulsory[4] = "0";
                IntCompulsory[5] = "0";
                IntCompulsory[6] = "0";
                IntCompulsory[7] = "0";
                IntCompulsory[8] = "0";
                IntCompulsory[9] = "0";
                IntCompulsory[10] = "0";
                IntCompulsory[11] = "0";
                IntCompulsory[12] = "0";
                IntCompulsory[13] = "0";
                IntCompulsory[14] = "0";

                IntTotal[0] = "0";
                IntTotal[1] = "0";
                IntTotal[2] = "0";
                IntTotal[3] = "0";
                IntTotal[4] = "0";
                IntTotal[5] = "0";
                IntTotal[6] = "0";
                IntTotal[7] = "0";
                IntTotal[8] = "0";
                IntTotal[9] = "0";
                IntTotal[10] = "0";
                IntTotal[11] = "0";
                IntTotal[12] = "0";
                IntTotal[13] = "0";
                IntTotal[14] = "0";

                //Marketing
                MktInsurer[0] = GetProvider(16);
                MktInsurer[1] = GetProvider(11);
                MktInsurer[2] = GetProvider(32);
                MktInsurer[3] = GetProvider(31);
                MktInsurer[4] = GetProvider(35);
                MktInsurer[5] = GetProvider(41);
                MktInsurer[6] = GetProvider(29);
                MktInsurer[7] = GetProvider(12);
                MktInsurer[8] = GetProvider(33);
                MktInsurer[9] = GetProvider(46);
                MktInsurer[10] = GetProvider(39);
                MktInsurer[11] = GetProvider(43);
                MktInsurer[12] = GetProvider(45);
                MktInsurer[13] = GetProvider(58);
                MktInsurer[14] = GetProvider(50);

                MktVoluntary[0] = "0";
                MktVoluntary[1] = "0";
                MktVoluntary[2] = "0";
                MktVoluntary[3] = "0";
                MktVoluntary[4] = "0";
                MktVoluntary[5] = "0";
                MktVoluntary[6] = "0";
                MktVoluntary[7] = "0";
                MktVoluntary[8] = "0";
                MktVoluntary[9] = "0";
                MktVoluntary[10] = "0";
                MktVoluntary[11] = "0";
                MktVoluntary[12] = "0";
                MktVoluntary[13] = "0";
                MktVoluntary[14] = "0";

                MktCompulsory[0] = "0";
                MktCompulsory[1] = "0";
                MktCompulsory[2] = "0";
                MktCompulsory[3] = "0";
                MktCompulsory[4] = "0";
                MktCompulsory[5] = "0";
                MktCompulsory[6] = "0";
                MktCompulsory[7] = "0";
                MktCompulsory[8] = "0";
                MktCompulsory[9] = "0";
                MktCompulsory[10] = "0";
                MktCompulsory[11] = "0";
                MktCompulsory[12] = "0";
                MktCompulsory[13] = "0";
                MktCompulsory[14] = "0";

                MktTotal[0] = "0";
                MktTotal[1] = "0";
                MktTotal[2] = "0";
                MktTotal[3] = "0";
                MktTotal[4] = "0";
                MktTotal[5] = "0";
                MktTotal[6] = "0";
                MktTotal[7] = "0";
                MktTotal[8] = "0";
                MktTotal[9] = "0";
                MktTotal[10] = "0";
                MktTotal[11] = "0";
                MktTotal[12] = "0";
                MktTotal[13] = "0";
                MktTotal[14] = "0";
                #endregion

                for (int i = 0; i < TotalFileCount; i++)
                {
                    #region Value Assign
                    fl_SalePremium = 0.0f;
                    str_NetPremium = "0";
                    str_GrossPremium = "0";
                    str_VAT = "0";
                    str_Duty = "0";
                    str_CNetPremium = "0";
                    str_CGrossPremium = "0";
                    str_CVAT = "0";
                    str_CDuty = "0";
                    str_DiscountToCustomer = "0";
                    int_PayCount = 0;
                    int_CCCount = 0;

                    QuoteRefNo[i] = _dtSummary.Rows[i]["QuoteRefNo"].ToString();
                    CECarId[i] = _dtSummary.Rows[i]["CECarId"].ToString();
                    ProviderCompanyId[i] = _dtSummary.Rows[i]["ProviderCompanyId"].ToString();
                    OrderDate[i] = _dtSummary.Rows[i]["OrderDate"].ToString();
                    CustomerType[i] = _dtSummary.Rows[i]["CustomerType"].ToString();
                    ApplicationName[i] = _dtSummary.Rows[i]["ApplicationName"].ToString();
                    Insurer[i] = _dtSummary.Rows[i]["Insurer"].ToString();
                    InsuranceType[i] = _dtSummary.Rows[i]["InsuranceType"].ToString();
                    InsuranceTypeId[i] = _dtSummary.Rows[i]["InsuranceTypeId"].ToString();
                    PolicyStartDate[i] = _dtSummary.Rows[i]["PolicyStartDate"].ToString();
                    PolicyEndDate[i] = _dtSummary.Rows[i]["PolicyEndDate"].ToString();
                    //SalesPremium[i] = _dtSummary.Rows[i]["Premium"].ToString();
                    CPolicyStartDate[i] = _dtSummary.Rows[i]["CTPLStartDate"].ToString();
                    CPolicyEndDate[i] = _dtSummary.Rows[i]["CTPLEndDate"].ToString();
                    CollectedPremium[i] = _dtSummary.Rows[i]["TotalCollectedPremium"].ToString();
                    Discount[i] = _dtSummary.Rows[i]["DiscountPercentage"].ToString() + "%";
                    Agent[i] = _dtSummary.Rows[i]["AgentName"].ToString();
                    IsCTPL[i] = _dtSummary.Rows[i]["IsCTPL"].ToString();
                    CTPL[i] = _dtSummary.Rows[i]["CTPL"].ToString();
                    GarageType[i] = _dtSummary.Rows[i]["GarageType"].ToString();

                    //fl_SalePremium = 54713.00f;
                    fl_SalePremium = Convert.ToSingle(_dtSummary.Rows[i]["SalesPremium"].ToString());
                    SalesPremium[i] = fl_SalePremium.ToString();
                    //str_NetPremium = Math.Ceiling(fl_SalePremium / 1.07).ToString();
                    //str_NetPremium = Math.Floor(Convert.ToSingle(str_NetPremium) / 1.004).ToString();
                    str_NetPremium = _dtSummary.Rows[i]["Premium"].ToString();
                    NetPremium[i] = str_NetPremium.ToString();
                    str_Duty = Math.Ceiling((Convert.ToSingle(str_NetPremium) * 0.004)).ToString();
                    Duty[i] = str_Duty.ToString();
                    str_VAT = Math.Round(((Convert.ToSingle(str_NetPremium) + Convert.ToSingle(str_Duty)) * 0.07), 2).ToString();
                    VAT[i] = str_VAT.ToString();
                    //str_GrossPremium = Math.Round((Convert.ToSingle(str_NetPremium) + Convert.ToSingle(str_Duty) + Convert.ToSingle(str_VAT)),2).ToString();
                    str_GrossPremium = _dtSummary.Rows[i]["GrossPremium"].ToString();
                    GrossPremium[i] = str_GrossPremium.ToString();

                    //if ("YES" == "YES")
                    if (_dtSummary.Rows[i]["IsCTPL"] != string.Empty && _dtSummary.Rows[i]["IsCTPL"].ToString().ToUpper() == "YES")
                    {
                        str_CGrossPremium = _dtSummary.Rows[i]["CTPL"].ToString();
                        CGrossPremium[i] = str_CGrossPremium.ToString();
                        str_CVAT = (Convert.ToSingle(str_CGrossPremium) / 1.07).ToString();
                        str_CVAT = Math.Round(Convert.ToSingle(str_CGrossPremium) - (Convert.ToSingle(str_CVAT)), 2).ToString();
                        CVAT[i] = str_CVAT.ToString();
                        str_CDuty = Math.Ceiling((Convert.ToSingle(str_CGrossPremium) / 1.07) * 0.004).ToString();
                        CDuty[i] = str_CDuty.ToString();
                        str_CNetPremium = (Convert.ToSingle(str_CGrossPremium) - (Convert.ToSingle(str_CDuty) + Convert.ToSingle(str_CVAT))).ToString();
                        CNetPremium[i] = str_CNetPremium.ToString();
                    }
                    else
                    {
                        CVAT[i] = " ";
                        CDuty[i] = " ";
                        CNetPremium[i] = " ";
                        CGrossPremium[i] = " ";
                    }
                    //str_DiscountToCustomer = Math.Round(((Convert.ToSingle(fl_SalePremium) + Convert.ToSingle(str_CGrossPremium)) - Convert.ToSingle(13718.00)), 2).ToString();
                    str_DiscountToCustomer = Math.Round(((Convert.ToSingle(fl_SalePremium) + Convert.ToSingle(str_CGrossPremium)) - Convert.ToSingle(CollectedPremium[i].ToString())), 2).ToString();
                    DiscounttoCustomer[i] = str_DiscountToCustomer.ToString();
                    Bank[i] = "BBL";
                    MethodofPayment[i] = " ";
                    BBLBankCharge[i] = "0";
                    VAT7[i] = "0";
                    BBLNetReceived[i] = "0";
                    Remark[i] = " ";
                    PremiumReceivingDate[i] = " ";
                    if (_dsSummary != null && _dsSummary.Tables.Count > 1 && _dsSummary.Tables[1].Rows.Count > 0)
                    {
                        string _PayDetails = GetPaymentDetailList(Convert.ToInt64(CECarId[i].ToString()), Convert.ToInt64(ProviderCompanyId[i].ToString()), CollectedPremium[i].ToString());
                        string[] _PayDetail = _PayDetails.Split('@');
                        if (_PayDetail.Length > 1)
                        {
                            MethodofPayment[i] = _PayDetail[0].ToString();
                            PremiumReceivingDate[i] = _PayDetail[1].ToString();
                        }
                        if (_PayDetail.Length > 5)
                        {
                            if (_PayDetail[2].ToString().Trim() != string.Empty)
                            {
                                if (_PayDetail[2].ToString().Trim() != "0" && _PayDetail[2].ToString().Trim() != "0.00")
                                {
                                    BBLBankCharge[i] = _PayDetail[2].ToString().Trim();
                                }
                                else
                                {
                                    BBLBankCharge[i] = " ";
                                }
                            }
                            if (_PayDetail[3].ToString().Trim() != string.Empty)
                            {
                                if (_PayDetail[3].ToString().Trim() != "0" && _PayDetail[3].ToString().Trim() != "0.00")
                                {
                                    VAT7[i] = _PayDetail[3].ToString().Trim();
                                }
                                else
                                {
                                    VAT7[i] = " ";
                                }
                            }
                            if (_PayDetail[4].ToString().Trim() != string.Empty)
                            {
                                BBLNetReceived[i] = _PayDetail[4].ToString().Trim();
                            }
                            if (_PayDetail[5].ToString().Trim() != string.Empty)
                            {
                                Bank[i] = _PayDetail[5].ToString().Trim();
                            }
                        }
                    }
                    if (_dsSummary != null && _dsSummary.Tables.Count > 2 && _dsSummary.Tables[2].Rows.Count > 0)
                    {
                        Remark[i] = GetRemarks(QuoteRefNo[i].ToString(), 200);// _dsSummary.Tables[2].Rows[0]["Remarks"].ToString();
                    }
                    if (str_NetPremium.ToString().Trim() != string.Empty)
                    {
                        TotalNetPremium = (Convert.ToSingle(TotalNetPremium) + Convert.ToSingle(str_NetPremium)).ToString();
                    }
                    if (str_CNetPremium.ToString().Trim() != string.Empty)
                    {
                        TotalCNetPremium = (Convert.ToSingle(TotalCNetPremium) + Convert.ToSingle(str_CNetPremium)).ToString();
                    }
                    if (CollectedPremium[i].ToString().Trim() != string.Empty)
                    {
                        TotalCollectedPremium = (Convert.ToSingle(TotalCollectedPremium) + Convert.ToSingle(CollectedPremium[i].ToString())).ToString();
                    }
                    if (BBLBankCharge[i].ToString().Trim() != string.Empty)
                    {
                        TotalBBLBankCharge = (Convert.ToSingle(TotalBBLBankCharge) + Convert.ToSingle(BBLBankCharge[i].ToString().Trim())).ToString();
                    }
                    if (VAT7[i].ToString().Trim() != string.Empty)
                    {
                        TotalVAT7 = (Convert.ToSingle(TotalVAT7) + Convert.ToSingle(VAT7[i].ToString().Trim())).ToString();
                    }
                    if (BBLNetReceived[i].ToString().Trim() != string.Empty)
                    {
                        TotalBBLNetReceived = (Convert.ToSingle(TotalBBLNetReceived) + Convert.ToSingle(BBLNetReceived[i].ToString().Trim())).ToString();
                    }

                    float _tempCollectedPremium = 0.0f;
                    float _tempBBLNetReceived = 0.0f;
                    if (!float.TryParse(CollectedPremium[i].ToString(), out _tempCollectedPremium))
                    {
                        _tempCollectedPremium = 0.0f;
                    }
                    if (!float.TryParse(BBLNetReceived[i].ToString(), out _tempBBLNetReceived))
                    {
                        _tempBBLNetReceived = 0.0f;
                    }
                    Difference[i] = (_tempBBLNetReceived - _tempCollectedPremium).ToString();
                    TotalDifference = (Convert.ToSingle(TotalDifference) + Convert.ToSingle(Difference[i].ToString().Trim())).ToString();
                    #endregion

                    #region Value for OIC & Internal Reports
                    float _IntPer = 0.0f;
                    float _MktPer = 0.0f;
                    float _OICPer = 0.0f;
                    DataTable _dtPer = new DataTable();
                    #region AXA
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "16")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(16, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntAXA = (Convert.ToSingle(C_IntAXA) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktAXA = (Convert.ToSingle(C_MktAXA) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICAXA = (Convert.ToSingle(C_OICAXA) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11"))
                        {
                            _dtPer = GetPercentage(16, "VMI", 1011, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAXA = (Convert.ToSingle(V_IntAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAXA = (Convert.ToSingle(V_MktAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAXA = (Convert.ToSingle(V_OICAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() != "10" && InsuranceTypeId[i].ToString().Trim() != "11"))
                        {
                            _dtPer = GetPercentage(16, "VMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAXA = (Convert.ToSingle(V_IntAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAXA = (Convert.ToSingle(V_MktAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAXA = (Convert.ToSingle(V_OICAXA) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntAXA = ((Convert.ToSingle(V_IntAXA)) + (Convert.ToSingle(C_IntAXA))).ToString();
                        Total_MktAXA = ((Convert.ToSingle(V_MktAXA)) + (Convert.ToSingle(C_MktAXA))).ToString();
                        Total_OICAXA = ((Convert.ToSingle(V_OICAXA)) + (Convert.ToSingle(C_OICAXA))).ToString();
                    }
                    #endregion

                    #region AZCP
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "11")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(11, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntAZCP = (Convert.ToSingle(C_IntAZCP) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktAZCP = (Convert.ToSingle(C_IntAZCP) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICAZCP = (Convert.ToSingle(C_IntAZCP) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11") && GarageType[i].ToString().Trim() == "1")
                        {
                            _dtPer = GetPercentage(11, "VMI", 1011, 1, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAZCP = (Convert.ToSingle(V_IntAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAZCP = (Convert.ToSingle(V_MktAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAZCP = (Convert.ToSingle(V_OICAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11") && GarageType[i].ToString().Trim() == "2")
                        {
                            _dtPer = GetPercentage(11, "VMI", 1011, 2, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAZCP = (Convert.ToSingle(V_IntAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAZCP = (Convert.ToSingle(V_MktAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAZCP = (Convert.ToSingle(V_OICAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() == "21" || InsuranceTypeId[i].ToString().Trim() == "31")
                        {
                            _dtPer = GetPercentage(11, "VMI", 2131, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAZCP = (Convert.ToSingle(V_IntAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAZCP = (Convert.ToSingle(V_MktAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAZCP = (Convert.ToSingle(V_OICAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() == "30")
                        {
                            _dtPer = GetPercentage(11, "VMI", 30, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntAZCP = (Convert.ToSingle(V_IntAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktAZCP = (Convert.ToSingle(V_MktAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICAZCP = (Convert.ToSingle(V_OICAZCP) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntAZCP = ((Convert.ToSingle(V_IntAZCP)) + (Convert.ToSingle(C_IntAZCP))).ToString();
                        Total_MktAZCP = ((Convert.ToSingle(V_MktAZCP)) + (Convert.ToSingle(C_MktAZCP))).ToString();
                        Total_OICAZCP = ((Convert.ToSingle(V_OICAZCP)) + (Convert.ToSingle(C_OICAZCP))).ToString();
                    }
                    #endregion

                    #region BKI
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "32")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(32, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntBKI = (Convert.ToSingle(C_IntBKI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktBKI = (Convert.ToSingle(C_MktBKI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICBKI = (Convert.ToSingle(C_OICBKI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        _dtPer = GetPercentage(32, "VMI", 0, 0, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                            _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                            _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());


                            V_IntBKI = (Convert.ToSingle(V_IntBKI) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                            V_MktBKI = (Convert.ToSingle(V_MktBKI) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                            V_OICBKI = (Convert.ToSingle(V_OICBKI) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                        }

                        Total_IntBKI = ((Convert.ToSingle(V_IntBKI)) + (Convert.ToSingle(C_IntBKI))).ToString();
                        Total_MktBKI = ((Convert.ToSingle(V_MktBKI)) + (Convert.ToSingle(C_MktBKI))).ToString();
                        Total_OICBKI = ((Convert.ToSingle(V_OICBKI)) + (Convert.ToSingle(C_OICBKI))).ToString();
                    }
                    #endregion

                    #region Chartis
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "31")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(31, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntCTS = (Convert.ToSingle(C_IntCTS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktCTS = (Convert.ToSingle(C_MktCTS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICCTS = (Convert.ToSingle(C_OICCTS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        _dtPer = GetPercentage(31, "VMI", 0, 0, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                            _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                            _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                            V_IntCTS = (Convert.ToSingle(V_IntCTS) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                            V_MktCTS = (Convert.ToSingle(V_MktCTS) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                            V_OICCTS = (Convert.ToSingle(V_OICCTS) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                        }

                        Total_IntCTS = ((Convert.ToSingle(V_IntCTS)) + (Convert.ToSingle(C_IntCTS))).ToString();
                        Total_MktCTS = ((Convert.ToSingle(V_MktCTS)) + (Convert.ToSingle(C_MktCTS))).ToString();
                        Total_OICCTS = ((Convert.ToSingle(V_OICCTS)) + (Convert.ToSingle(C_OICCTS))).ToString();
                    }
                    #endregion

                    #region Kurnia
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "41")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(41, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntKUR = (Convert.ToSingle(C_IntKUR) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktKUR = (Convert.ToSingle(C_MktKUR) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICKUR = (Convert.ToSingle(C_OICKUR) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() != "11")
                        {
                            _dtPer = GetPercentage(41, "VMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntKUR = (Convert.ToSingle(V_IntKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktKUR = (Convert.ToSingle(V_MktKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICKUR = (Convert.ToSingle(V_OICKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() == "11")
                        {
                            _dtPer = GetPercentage(41, "VMI", 11, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntKUR = (Convert.ToSingle(V_IntKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktKUR = (Convert.ToSingle(V_MktKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICKUR = (Convert.ToSingle(V_OICKUR) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntKUR = ((Convert.ToSingle(V_IntKUR)) + (Convert.ToSingle(C_IntKUR))).ToString();
                        Total_MktKUR = ((Convert.ToSingle(V_MktKUR)) + (Convert.ToSingle(C_MktKUR))).ToString();
                        Total_OICKUR = ((Convert.ToSingle(V_OICKUR)) + (Convert.ToSingle(C_OICKUR))).ToString();
                    }
                    #endregion

                    #region LMG
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "29")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(29, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntLMG = (Convert.ToSingle(C_IntLMG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktLMG = (Convert.ToSingle(C_MktLMG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICLMG = (Convert.ToSingle(C_OICLMG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11"))
                        {
                            _dtPer = GetPercentage(29, "VMI", 1011, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntLMG = (Convert.ToSingle(V_IntLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktLMG = (Convert.ToSingle(V_MktLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICLMG = (Convert.ToSingle(V_OICLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() != "10" && InsuranceTypeId[i].ToString().Trim() != "11"))
                        {
                            _dtPer = GetPercentage(29, "VMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntLMG = (Convert.ToSingle(V_IntLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktLMG = (Convert.ToSingle(V_MktLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICLMG = (Convert.ToSingle(V_OICLMG) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntLMG = ((Convert.ToSingle(V_IntLMG)) + (Convert.ToSingle(C_IntLMG))).ToString();
                        Total_MktLMG = ((Convert.ToSingle(V_MktLMG)) + (Convert.ToSingle(C_MktLMG))).ToString();
                        Total_OICLMG = ((Convert.ToSingle(V_OICLMG)) + (Convert.ToSingle(C_OICLMG))).ToString();
                    }
                    #endregion

                    #region MSIG
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "12")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(12, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntMSIG = (Convert.ToSingle(C_IntMSIG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktMSIG = (Convert.ToSingle(C_MktMSIG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICMSIG = (Convert.ToSingle(C_OICMSIG) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        _dtPer = GetPercentage(12, "VMI", 0, 0, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                            _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                            _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                            V_IntMSIG = (Convert.ToSingle(V_IntMSIG) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                            V_MktMSIG = (Convert.ToSingle(V_MktMSIG) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                            V_OICMSIG = (Convert.ToSingle(V_OICMSIG) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                        }

                        Total_IntMSIG = ((Convert.ToSingle(V_IntMSIG)) + (Convert.ToSingle(C_IntMSIG))).ToString();
                        Total_MktMSIG = ((Convert.ToSingle(V_MktMSIG)) + (Convert.ToSingle(C_MktMSIG))).ToString();
                        Total_OICMSIG = ((Convert.ToSingle(V_OICMSIG)) + (Convert.ToSingle(C_OICMSIG))).ToString();
                    }
                    #endregion

                    #region MuangThai
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "33")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(33, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntMTI = (Convert.ToSingle(C_IntMTI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktMTI = (Convert.ToSingle(C_IntMTI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICMTI = (Convert.ToSingle(C_IntMTI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11"))
                        {
                            _dtPer = GetPercentage(33, "VMI", 1011, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntMTI = (Convert.ToSingle(V_IntMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktMTI = (Convert.ToSingle(V_MktMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICMTI = (Convert.ToSingle(V_OICMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() == "21" || InsuranceTypeId[i].ToString().Trim() == "31")
                        {
                            _dtPer = GetPercentage(33, "VMI", 2131, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntMTI = (Convert.ToSingle(V_IntMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktMTI = (Convert.ToSingle(V_MktMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICMTI = (Convert.ToSingle(V_OICMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && InsuranceTypeId[i].ToString().Trim() == "30")
                        {
                            _dtPer = GetPercentage(33, "VMI", 30, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntMTI = (Convert.ToSingle(V_IntMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktMTI = (Convert.ToSingle(V_MktMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICMTI = (Convert.ToSingle(V_OICMTI) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntMTI = ((Convert.ToSingle(V_IntMTI)) + (Convert.ToSingle(C_IntMTI))).ToString();
                        Total_MktMTI = ((Convert.ToSingle(V_MktMTI)) + (Convert.ToSingle(C_MktMTI))).ToString();
                        Total_OICMTI = ((Convert.ToSingle(V_OICMTI)) + (Convert.ToSingle(C_OICMTI))).ToString();
                    }
                    #endregion

                    #region Tokio Marine
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "46")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(46, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntTMS = (Convert.ToSingle(C_IntTMS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktTMS = (Convert.ToSingle(C_MktTMS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICTMS = (Convert.ToSingle(C_OICTMS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11"))
                        {
                            _dtPer = GetPercentage(46, "VMI", 1011, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntTMS = (Convert.ToSingle(V_IntTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktTMS = (Convert.ToSingle(V_MktTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICTMS = (Convert.ToSingle(V_OICTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() != "10" && InsuranceTypeId[i].ToString().Trim() != "11"))
                        {
                            _dtPer = GetPercentage(46, "VMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntTMS = (Convert.ToSingle(V_IntTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktTMS = (Convert.ToSingle(V_MktTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICTMS = (Convert.ToSingle(V_OICTMS) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntTMS = ((Convert.ToSingle(V_IntTMS)) + (Convert.ToSingle(C_IntTMS))).ToString();
                        Total_MktTMS = ((Convert.ToSingle(V_MktTMS)) + (Convert.ToSingle(C_MktTMS))).ToString();
                        Total_OICTMS = ((Convert.ToSingle(V_OICTMS)) + (Convert.ToSingle(C_OICTMS))).ToString();
                    }
                    #endregion

                    #region KrungThai
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "35")                    
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(35, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntKPI = (Convert.ToSingle(C_IntKPI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktKPI = (Convert.ToSingle(C_MktKPI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICKPI = (Convert.ToSingle(C_OICKPI) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11"))
                        {
                            _dtPer = GetPercentage(35, "VMI", 1011, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntKPI = (Convert.ToSingle(V_IntKPI) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktKPI = (Convert.ToSingle(V_MktKPI) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICKPI = (Convert.ToSingle(V_OICKPI) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() != "10" && InsuranceTypeId[i].ToString().Trim() != "11"))
                        {
                            _dtPer = GetPercentage(35, "VMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntKPI = (Convert.ToSingle(V_IntKPI) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktKPI = (Convert.ToSingle(V_MktKPI) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICKPI = (Convert.ToSingle(V_OICKPI) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }

                        Total_IntKPI = ((Convert.ToSingle(V_IntKPI)) + (Convert.ToSingle(C_IntKPI))).ToString();
                        Total_MktKPI = ((Convert.ToSingle(V_MktKPI)) + (Convert.ToSingle(C_MktKPI))).ToString();
                        Total_OICKPI = ((Convert.ToSingle(V_OICKPI)) + (Convert.ToSingle(C_OICKPI))).ToString();
                    }
                    #endregion

                    #region Mittare
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "39")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(39, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntMIR = (Convert.ToSingle(C_IntMIR) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktMIR = (Convert.ToSingle(C_MktMIR) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICMIR = (Convert.ToSingle(C_OICMIR) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        _dtPer = GetPercentage(39, "VMI", 0, 0, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                            _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                            _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());


                            V_IntMIR = (Convert.ToSingle(V_IntMIR) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                            V_MktMIR = (Convert.ToSingle(V_MktMIR) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                            V_OICMIR = (Convert.ToSingle(V_OICMIR) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                        }

                        Total_IntMIR = ((Convert.ToSingle(V_IntMIR)) + (Convert.ToSingle(C_IntMIR))).ToString();
                        Total_MktMIR = ((Convert.ToSingle(V_MktMIR)) + (Convert.ToSingle(C_MktMIR))).ToString();
                        Total_OICMIR = ((Convert.ToSingle(V_OICMIR)) + (Convert.ToSingle(C_OICMIR))).ToString();
                    }
                    #endregion

                    #region Syn Mun Kong
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "43")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(43, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntSMK = (Convert.ToSingle(C_IntSMK) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktSMK = (Convert.ToSingle(C_MktSMK) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICSMK = (Convert.ToSingle(C_OICSMK) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        _dtPer = GetPercentage(43, "VMI", 0, 0, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                            _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                            _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());


                            V_IntSMK = (Convert.ToSingle(V_IntSMK) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                            V_MktSMK = (Convert.ToSingle(V_MktSMK) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                            V_OICSMK = (Convert.ToSingle(V_OICSMK) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                        }

                        Total_IntSMK = ((Convert.ToSingle(V_IntSMK)) + (Convert.ToSingle(C_IntSMK))).ToString();
                        Total_MktSMK = ((Convert.ToSingle(V_MktSMK)) + (Convert.ToSingle(C_MktSMK))).ToString();
                        Total_OICSMK = ((Convert.ToSingle(V_OICSMK)) + (Convert.ToSingle(C_OICSMK))).ToString();
                    }
                    #endregion

                    #region Viriyah
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "45")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(45, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntVRY = (Convert.ToSingle(C_IntVRY) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktVRY = (Convert.ToSingle(C_MktVRY) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICVRY = (Convert.ToSingle(C_OICVRY) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        _dtPer = GetPercentage(45, "VMI", 0, 0, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                            _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                            _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());


                            V_IntVRY = (Convert.ToSingle(V_IntVRY) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                            V_MktVRY = (Convert.ToSingle(V_MktVRY) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                            V_OICVRY = (Convert.ToSingle(V_OICVRY) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                        }

                        Total_IntVRY = ((Convert.ToSingle(V_IntVRY)) + (Convert.ToSingle(C_IntVRY))).ToString();
                        Total_MktVRY = ((Convert.ToSingle(V_MktVRY)) + (Convert.ToSingle(C_MktVRY))).ToString();
                        Total_OICVRY = ((Convert.ToSingle(V_OICVRY)) + (Convert.ToSingle(C_OICVRY))).ToString();
                    }
                    #endregion

                    #region Thaivivat
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "58")
                    {
                        if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(58, "CMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                C_IntTVV = (Convert.ToSingle(C_IntTVV) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                C_MktTVV = (Convert.ToSingle(C_MktTVV) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                C_OICTVV = (Convert.ToSingle(C_OICTVV) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        _dtPer = GetPercentage(58, "VMI", 0, 0, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                            _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                            _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());


                            V_IntTVV = (Convert.ToSingle(V_IntTVV) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                            V_MktTVV = (Convert.ToSingle(V_MktTVV) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                            V_OICTVV = (Convert.ToSingle(V_OICTVV) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                        }

                        Total_IntTVV = ((Convert.ToSingle(V_IntTVV)) + (Convert.ToSingle(C_IntTVV))).ToString();
                        Total_MktTVV = ((Convert.ToSingle(V_MktTVV)) + (Convert.ToSingle(C_MktTVV))).ToString();
                        Total_OICTVV = ((Convert.ToSingle(V_OICTVV)) + (Convert.ToSingle(C_OICTVV))).ToString();
                    }
                    #endregion

                    #region SCSMG
                    if (ProviderCompanyId[i].ToString() != string.Empty && ProviderCompanyId[i].ToString().Trim() == "50")
                    {                        
                        if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() == "10" || InsuranceTypeId[i].ToString().Trim() == "11"))
                        {
                            if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                            {
                                _dtPer = GetPercentage(50, "CMI", 1011, 0, txtReportDate.Text.Trim());
                                if (_dtPer != null && _dtPer.Rows.Count > 0)
                                {
                                    _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                    _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                    _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                    C_IntSCS = (Convert.ToSingle(C_IntSCS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                    C_MktSCS = (Convert.ToSingle(C_MktSCS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                    C_OICSCS = (Convert.ToSingle(C_OICSCS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                                }
                            }

                            _dtPer = GetPercentage(50, "VMI", 1011, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntSCS = (Convert.ToSingle(V_IntSCS) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktSCS = (Convert.ToSingle(V_MktSCS) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICSCS = (Convert.ToSingle(V_OICSCS) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        else if (InsuranceTypeId[i].ToString() != string.Empty && (InsuranceTypeId[i].ToString().Trim() != "10" && InsuranceTypeId[i].ToString().Trim() != "11"))
                        {
                            if (IsCTPL[i].ToString() != string.Empty && IsCTPL[i].ToString().ToUpper() == "YES")
                            {
                                _dtPer = GetPercentage(50, "CMI", 0, 0, txtReportDate.Text.Trim());
                                if (_dtPer != null && _dtPer.Rows.Count > 0)
                                {
                                    _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                    _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                    _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                    C_IntSCS = (Convert.ToSingle(C_IntSCS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _IntPer), 2)).ToString();
                                    C_MktSCS = (Convert.ToSingle(C_MktSCS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _MktPer), 2)).ToString();
                                    C_OICSCS = (Convert.ToSingle(C_OICSCS) + Math.Round((Convert.ToSingle(str_CNetPremium) * _OICPer), 2)).ToString();
                                }
                            }

                            _dtPer = GetPercentage(50, "VMI", 0, 0, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                _IntPer = Convert.ToSingle(_dtPer.Rows[0]["IternalCommission"].ToString());
                                _MktPer = Convert.ToSingle(_dtPer.Rows[0]["MarketingCommission"].ToString());
                                _OICPer = Convert.ToSingle(_dtPer.Rows[0]["OICCommission"].ToString());

                                V_IntSCS = (Convert.ToSingle(V_IntSCS) + Math.Round((Convert.ToSingle(str_NetPremium) * _IntPer), 2)).ToString();
                                V_MktSCS = (Convert.ToSingle(V_MktSCS) + Math.Round((Convert.ToSingle(str_NetPremium) * _MktPer), 2)).ToString();
                                V_OICSCS = (Convert.ToSingle(V_OICSCS) + Math.Round((Convert.ToSingle(str_NetPremium) * _OICPer), 2)).ToString();
                            }
                        }
                        Total_IntSCS = ((Convert.ToSingle(V_IntSCS)) + (Convert.ToSingle(C_IntSCS))).ToString();
                        Total_MktSCS = ((Convert.ToSingle(V_MktSCS)) + (Convert.ToSingle(C_MktSCS))).ToString();
                        Total_OICSCS = ((Convert.ToSingle(V_OICSCS)) + (Convert.ToSingle(C_OICSCS))).ToString();
                    }
                    #endregion

                    #endregion

                }

                #region Assign Value for OIC & Internal Reports
                OICVoluntaryTotal = (Convert.ToSingle(V_OICAZCP) + Convert.ToSingle(V_OICAXA) + Convert.ToSingle(V_OICBKI) + Convert.ToSingle(V_OICCTS) + Convert.ToSingle(V_OICKUR)
                                    + Convert.ToSingle(V_OICMTI) + Convert.ToSingle(V_OICLMG) + Convert.ToSingle(V_OICMSIG) + Convert.ToSingle(V_OICTMS) + Convert.ToSingle(V_OICKPI)
                                    + Convert.ToSingle(V_OICMIR) + Convert.ToSingle(V_OICSMK) + Convert.ToSingle(V_OICVRY) + Convert.ToSingle(V_OICTVV) + Convert.ToSingle(V_OICSCS)).ToString();

                OICCompulsoryTotal = (Convert.ToSingle(C_OICAZCP) + Convert.ToSingle(C_OICAXA) + Convert.ToSingle(C_OICBKI) + Convert.ToSingle(C_OICCTS) + Convert.ToSingle(C_OICKUR)
                                    + Convert.ToSingle(C_OICMTI) + Convert.ToSingle(C_OICLMG) + Convert.ToSingle(C_OICMSIG) + Convert.ToSingle(C_OICTMS) + Convert.ToSingle(C_OICKPI)
                                    + Convert.ToSingle(C_OICMIR) + Convert.ToSingle(C_OICSMK) + Convert.ToSingle(C_OICVRY) + Convert.ToSingle(C_OICTVV) + Convert.ToSingle(C_OICSCS)).ToString();

                OICFinalTotal = (Convert.ToSingle(Total_OICAZCP) + Convert.ToSingle(Total_OICAXA) + Convert.ToSingle(Total_OICBKI) + Convert.ToSingle(Total_OICCTS) + Convert.ToSingle(Total_OICKUR)
                                    + Convert.ToSingle(Total_OICMTI) + Convert.ToSingle(Total_OICLMG) + Convert.ToSingle(Total_OICMSIG) + Convert.ToSingle(Total_OICTMS) + Convert.ToSingle(Total_OICKPI)
                                    + Convert.ToSingle(Total_OICMIR) + Convert.ToSingle(Total_OICSMK) + Convert.ToSingle(Total_OICVRY) + Convert.ToSingle(Total_OICTVV) + Convert.ToSingle(Total_OICSCS)).ToString();

                IntVoluntaryTotal = (Convert.ToSingle(V_IntAZCP) + Convert.ToSingle(V_IntAXA) + Convert.ToSingle(V_IntBKI) + Convert.ToSingle(V_IntCTS) + Convert.ToSingle(V_IntKUR)
                                    + Convert.ToSingle(V_IntMTI) + Convert.ToSingle(V_IntLMG) + Convert.ToSingle(V_IntMSIG) + Convert.ToSingle(V_IntTMS) + Convert.ToSingle(V_IntKPI)
                                    + Convert.ToSingle(V_IntMIR) + Convert.ToSingle(V_IntSMK) + Convert.ToSingle(V_IntVRY) + Convert.ToSingle(V_IntTVV) + Convert.ToSingle(V_IntSCS)).ToString();
                
                IntCompulsoryTotal = (Convert.ToSingle(C_IntAZCP) + Convert.ToSingle(C_IntAXA) + Convert.ToSingle(C_IntBKI) + Convert.ToSingle(C_IntCTS) + Convert.ToSingle(C_IntKUR)
                                    + Convert.ToSingle(C_IntMTI) + Convert.ToSingle(C_IntLMG) + Convert.ToSingle(C_IntMSIG) + Convert.ToSingle(C_IntTMS) + Convert.ToSingle(C_IntKPI)
                                    + Convert.ToSingle(C_IntMIR) + Convert.ToSingle(C_IntSMK) + Convert.ToSingle(C_IntVRY) + Convert.ToSingle(C_IntTVV) + Convert.ToSingle(C_IntSCS)).ToString();
                
                IntFinalTotal = (Convert.ToSingle(Total_IntAZCP) + Convert.ToSingle(Total_IntAXA) + Convert.ToSingle(Total_IntBKI) + Convert.ToSingle(Total_IntCTS) + Convert.ToSingle(Total_IntKUR)
                                    + Convert.ToSingle(Total_IntMTI) + Convert.ToSingle(Total_IntLMG) + Convert.ToSingle(Total_IntMSIG) + Convert.ToSingle(Total_IntTMS) + Convert.ToSingle(Total_IntKPI)
                                    + Convert.ToSingle(Total_IntMIR) + Convert.ToSingle(Total_IntSMK) + Convert.ToSingle(Total_IntVRY) + Convert.ToSingle(Total_IntTVV) + Convert.ToSingle(Total_IntSCS)).ToString();

                MktVoluntaryTotal = (Convert.ToSingle(V_MktAZCP) + Convert.ToSingle(V_MktAXA) + Convert.ToSingle(V_MktBKI) + Convert.ToSingle(V_MktCTS) + Convert.ToSingle(V_MktKUR)
                                    + Convert.ToSingle(V_MktMTI) + Convert.ToSingle(V_MktLMG) + Convert.ToSingle(V_MktMSIG) + Convert.ToSingle(V_MktTMS) + Convert.ToSingle(V_MktKPI)
                                    + Convert.ToSingle(V_MktMIR) + Convert.ToSingle(V_MktSMK) + Convert.ToSingle(V_MktVRY) + Convert.ToSingle(V_MktTVV) + Convert.ToSingle(V_MktSCS)).ToString();
                
                MktCompulsoryTotal = (Convert.ToSingle(C_MktAZCP) + Convert.ToSingle(C_MktAXA) + Convert.ToSingle(C_MktBKI) + Convert.ToSingle(C_MktCTS) + Convert.ToSingle(C_MktKUR)
                                    + Convert.ToSingle(C_MktMTI) + Convert.ToSingle(C_MktLMG) + Convert.ToSingle(C_MktMSIG) + Convert.ToSingle(C_MktTMS) + Convert.ToSingle(C_MktKPI)
                                    + Convert.ToSingle(C_MktMIR) + Convert.ToSingle(C_MktSMK) + Convert.ToSingle(C_MktVRY) + Convert.ToSingle(C_MktTVV) + Convert.ToSingle(C_MktSCS)).ToString();
                
                MktFinalTotal = (Convert.ToSingle(Total_MktAZCP) + Convert.ToSingle(Total_MktAXA) + Convert.ToSingle(Total_MktBKI) + Convert.ToSingle(Total_MktCTS) + Convert.ToSingle(Total_MktKUR)
                                    + Convert.ToSingle(Total_MktMTI) + Convert.ToSingle(Total_MktLMG) + Convert.ToSingle(Total_MktMSIG) + Convert.ToSingle(Total_MktTMS) + Convert.ToSingle(Total_MktKPI)
                                    + Convert.ToSingle(Total_MktMIR) + Convert.ToSingle(Total_MktSMK) + Convert.ToSingle(Total_MktVRY) + Convert.ToSingle(Total_MktTVV) + Convert.ToSingle(Total_MktSCS)).ToString();

                //OIC
                OICVoluntary[0] = V_OICAXA.ToString();
                OICVoluntary[1] = V_OICAZCP.ToString();
                OICVoluntary[2] = V_OICBKI.ToString();
                OICVoluntary[3] = V_OICCTS.ToString();
                OICVoluntary[4] = V_OICKPI.ToString();
                OICVoluntary[5] = V_OICKUR.ToString();
                OICVoluntary[6] = V_OICLMG.ToString();
                OICVoluntary[7] = V_OICMSIG.ToString();
                OICVoluntary[8] = V_OICMTI.ToString();
                OICVoluntary[9] = V_OICTMS.ToString();
                OICVoluntary[10] = V_OICMIR.ToString();
                OICVoluntary[11] = V_OICSMK.ToString();
                OICVoluntary[12] = V_OICVRY.ToString();
                OICVoluntary[13] = V_OICTVV.ToString();
                OICVoluntary[14] = V_OICSCS.ToString();

                OICCompulsory[0] = C_OICAXA.ToString();
                OICCompulsory[1] = C_OICAZCP.ToString();
                OICCompulsory[2] = C_OICBKI.ToString();
                OICCompulsory[3] = C_OICCTS.ToString();
                OICCompulsory[4] = C_OICKPI.ToString();
                OICCompulsory[5] = C_OICKUR.ToString();
                OICCompulsory[6] = C_OICLMG.ToString();
                OICCompulsory[7] = C_OICMSIG.ToString();
                OICCompulsory[8] = C_OICMTI.ToString();
                OICCompulsory[9] = C_OICTMS.ToString();
                OICCompulsory[10] = C_OICMIR.ToString();
                OICCompulsory[11] = C_OICSMK.ToString();
                OICCompulsory[12] = C_OICVRY.ToString();
                OICCompulsory[13] = C_OICTVV.ToString();
                OICCompulsory[14] = C_OICSCS.ToString();

                OICTotal[0] = Total_OICAXA.ToString();
                OICTotal[1] = Total_OICAZCP.ToString();
                OICTotal[2] = Total_OICBKI.ToString();
                OICTotal[3] = Total_OICCTS.ToString();
                OICTotal[4] = Total_OICKPI.ToString();
                OICTotal[5] = Total_OICKUR.ToString();
                OICTotal[6] = Total_OICLMG.ToString();
                OICTotal[7] = Total_OICMSIG.ToString();
                OICTotal[8] = Total_OICMTI.ToString();
                OICTotal[9] = Total_OICTMS.ToString();
                OICTotal[10] = Total_OICMIR.ToString();
                OICTotal[11] = Total_OICSMK.ToString();
                OICTotal[12] = Total_OICVRY.ToString();
                OICTotal[13] = Total_OICTVV.ToString();
                OICTotal[14] = Total_OICSCS.ToString();

                //Intenal
                IntVoluntary[0] = V_IntAXA.ToString();
                IntVoluntary[1] = V_IntAZCP.ToString();
                IntVoluntary[2] = V_IntBKI.ToString();
                IntVoluntary[3] = V_IntCTS.ToString();
                IntVoluntary[4] = V_IntKPI.ToString();
                IntVoluntary[5] = V_IntKUR.ToString();
                IntVoluntary[6] = V_IntLMG.ToString();
                IntVoluntary[7] = V_IntMSIG.ToString();
                IntVoluntary[8] = V_IntMTI.ToString();
                IntVoluntary[9] = V_IntTMS.ToString();
                IntVoluntary[10] = V_IntMIR.ToString();
                IntVoluntary[11] = V_IntSMK.ToString();
                IntVoluntary[12] = V_IntVRY.ToString();
                IntVoluntary[13] = V_IntTVV.ToString();
                IntVoluntary[14] = V_IntSCS.ToString();

                IntCompulsory[0] = C_IntAXA.ToString();
                IntCompulsory[1] = C_IntAZCP.ToString();
                IntCompulsory[2] = C_IntBKI.ToString();
                IntCompulsory[3] = C_IntCTS.ToString();
                IntCompulsory[4] = C_IntKPI.ToString();
                IntCompulsory[5] = C_IntKUR.ToString();
                IntCompulsory[6] = C_IntLMG.ToString();
                IntCompulsory[7] = C_IntMSIG.ToString();
                IntCompulsory[8] = C_IntMTI.ToString();
                IntCompulsory[9] = C_IntTMS.ToString();
                IntCompulsory[10] = C_IntMIR.ToString();
                IntCompulsory[11] = C_IntSMK.ToString();
                IntCompulsory[12] = C_IntVRY.ToString();
                IntCompulsory[13] = C_IntTVV.ToString();
                IntCompulsory[14] = C_IntSCS.ToString();

                IntTotal[0] = Total_IntAXA.ToString();
                IntTotal[1] = Total_IntAZCP.ToString();
                IntTotal[2] = Total_IntBKI.ToString();
                IntTotal[3] = Total_IntCTS.ToString();
                IntTotal[4] = Total_IntKPI.ToString();
                IntTotal[5] = Total_IntKUR.ToString();
                IntTotal[6] = Total_IntLMG.ToString();
                IntTotal[7] = Total_IntMSIG.ToString();
                IntTotal[8] = Total_IntMTI.ToString();
                IntTotal[9] = Total_IntTMS.ToString();
                IntTotal[10] = Total_IntMIR.ToString();
                IntTotal[11] = Total_IntSMK.ToString();
                IntTotal[12] = Total_IntVRY.ToString();
                IntTotal[13] = Total_IntTVV.ToString();
                IntTotal[14] = Total_IntSCS.ToString();

                //Marketing
                MktVoluntary[0] = V_MktAXA.ToString();
                MktVoluntary[1] = V_MktAZCP.ToString();
                MktVoluntary[2] = V_MktBKI.ToString();
                MktVoluntary[3] = V_MktCTS.ToString();
                MktVoluntary[4] = V_MktKPI.ToString();
                MktVoluntary[5] = V_MktKUR.ToString();
                MktVoluntary[6] = V_MktLMG.ToString();
                MktVoluntary[7] = V_MktMSIG.ToString();
                MktVoluntary[8] = V_MktMTI.ToString();
                MktVoluntary[9] = V_MktTMS.ToString();
                MktVoluntary[10] = V_MktMIR.ToString();
                MktVoluntary[11] = V_MktSMK.ToString();
                MktVoluntary[12] = V_MktVRY.ToString();
                MktVoluntary[13] = V_MktTVV.ToString();
                MktVoluntary[14] = V_MktSCS.ToString();

                MktCompulsory[0] = C_MktAXA.ToString();
                MktCompulsory[1] = C_MktAZCP.ToString();
                MktCompulsory[2] = C_MktBKI.ToString();
                MktCompulsory[3] = C_MktCTS.ToString();
                MktCompulsory[4] = C_MktKPI.ToString();
                MktCompulsory[5] = C_MktKUR.ToString();
                MktCompulsory[6] = C_MktLMG.ToString();
                MktCompulsory[7] = C_MktMSIG.ToString();
                MktCompulsory[8] = C_MktMTI.ToString();
                MktCompulsory[9] = C_MktTMS.ToString();
                MktCompulsory[10] = C_MktMIR.ToString();
                MktCompulsory[11] = C_MktSMK.ToString();
                MktCompulsory[12] = C_MktVRY.ToString();
                MktCompulsory[13] = C_MktTVV.ToString();
                MktCompulsory[14] = C_MktSCS.ToString();

                MktTotal[0] = Total_MktAXA.ToString();
                MktTotal[1] = Total_MktAZCP.ToString();
                MktTotal[2] = Total_MktBKI.ToString();
                MktTotal[3] = Total_MktCTS.ToString();
                MktTotal[4] = Total_MktKPI.ToString();
                MktTotal[5] = Total_MktKUR.ToString();
                MktTotal[6] = Total_MktLMG.ToString();
                MktTotal[7] = Total_MktMSIG.ToString();
                MktTotal[8] = Total_MktMTI.ToString();
                MktTotal[9] = Total_MktTMS.ToString();
                MktTotal[10] = Total_MktMIR.ToString();
                MktTotal[11] = Total_MktSMK.ToString();
                MktTotal[12] = Total_MktVRY.ToString();
                MktTotal[13] = Total_MktTVV.ToString();
                MktTotal[14] = Total_MktSCS.ToString();

                #endregion

                #region Generate Excel
                string ReportMonth = "";
                if (_ReportType == 0)
                {
                    ReportMonth = GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                }
                else if (_ReportType == 1)
                {
                    ReportMonth = ddlDay1.Text + " " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                }
                else if (_ReportType == 3)
                {
                    ReportMonth = "01 " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text +  " TO 15 " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                }
                else if (_ReportType == 4)
                {
                    ReportMonth = "16 " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text + " TO " + LastDayOfMonth("16/" + ddlMonth1.Text + "/" + ddlYear1.Text) + " " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                }
                _html += "<html>";
                _html += "<head>";
                _html += "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>";
                _html += "</head>";
                _html += "<body>";
                _html += "<table width='100%' cellpadding='1' cellspacing='1' border='1'>";
                if (ddlLanguage.Text == "1")
                {
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        if (ddlProvider.Text == "0")
                        {
                            _html += "<tr><td align='left' colspan='31' style='font-size:20px; background-color:#D8D8D8;'><b>ยอดขายรวม (" + ReportMonth + ")</b></td></tr>";
                        }
                        else
                        {
                            _html += "<tr><td align='left' colspan='31' style='font-size:20px; background-color:#D8D8D8;'><b>ยอดขายรวม (" + ReportMonth + ") - " + GetProviderName(Convert.ToInt64(ddlProvider.Text),ddlLanguage.Text) + "</b></td></tr>";
                        }
                    }
                    else
                    {
                         if (ddlProvider.Text == "0")
                        {
                            _html += "<tr><td align='left' colspan='30' style='font-size:20px; background-color:#D8D8D8;'><b>ยอดขายรวม (" + ReportMonth + ")</b></td></tr>";
                        }
                         else
                         {
                             _html += "<tr><td align='left' colspan='30' style='font-size:20px; background-color:#D8D8D8;'><b>ยอดขายรวม (" + ReportMonth + ") - " + GetProviderName(Convert.ToInt64(ddlProvider.Text), ddlLanguage.Text) + "</b></td></tr>";
                         }
                    }
                    _html += "<tr>";
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        _html += "<td colspan='6'>&nbsp;</td>";
                    }
                    else
                    {
                        _html += "<td colspan='5'>&nbsp;</td>";
                    }
                    _html += "<td colspan='7' align='center' style='background-color:#fffe97;'><b>สมัครใจ</b></td>";
                    _html += "<td colspan='6' align='center' style='background-color:#cbffce;'><b>บังคับ</b></td>";
                    _html += "<td colspan='5'>&nbsp;</td>";
                    _html += "<td colspan='6' align='center' style='background-color:#c9ffff;'><b>รายการเงินฝากถอนในบัญชีเงินฝาก</b></td>";
                    _html += "</tr>";
                    _html += "<tr>";
                    _html += "<td width='80' align='left' style='font-size:14px; background-color:#81BEF7;'><b>วันที่ทำรายการ</b></td>";
                    _html += "<td width='90' align='left' style='font-size:14px; background-color:#81BEF7;'><b>เลขที่อ้างอืง</b></td>";
                    _html += "<td width='110' align='left' style='font-size:14px; background-color:#81BEF7;'><b>ประเภทลูกค้า</b></td>";
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        _html += "<td width='200' align='left' style='font-size:14px; background-color:#81BEF7;'><b>ชื่อผู้สมัคร</b></td>";
                    }
                    _html += "<td width='70' align='left' style='font-size:14px; background-color:#81BEF7;'><b>บริษัทประกันภัย</b></td>";
                    _html += "<td width='100' align='left' style='font-size:14px; background-color:#81BEF7;'><b>ประเภทประกันภัย</b></td>";
                    _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>วันเริ่มความคุ้มครอง</b></td>";
                    _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>วันสิ้นสุดกรมธรรม์</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>เบี้ยประกันภัย</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>ยอดรวมเบี้ยประกันภัย</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>เบี้ยประกันภัย</b></td>";
                    _html += "<td width='60' align='center' style='font-size:14px; background-color:#81BEF7;'><b>อากร</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>ภาษีมูลค่าเพิ่ม</b></td>";
                    _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>วันเริ่มความคุ้มครอง</b></td>";
                    _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>วันสิ้นสุดกรมธรรม์</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>เบี้ยประกันภัย</b></td>";
                    _html += "<td width='60' align='center' style='font-size:14px; background-color:#81BEF7;'><b>อากร</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>ภาษีมูลค่าเพิ่ม</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>ยอดรวมเบี้ยประกันภัย</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>เบี้ยประกันภัยรวมสุทธิ</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>ลดราคาสำหรับลูกค้า</b></td>";
                    _html += "<td width='70' align='left' style='font-size:14px; background-color:#81BEF7;'><b>ส่วนลด</b></td>";
                    _html += "<td width='130' align='left' style='font-size:14px; background-color:#81BEF7;'><b>เอเย่นต์</b></td>";
                    _html += "<td width='200' align='center' style='font-size:14px; background-color:#81BEF7;'><b>หมายเหต</b></td>";
                    _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>วันที่รับเบี้ยประกัน</b></td>";
                    _html += "<td width='60' align='center' style='font-size:14px; background-color:#81BEF7;'><b>ธนาคาร</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>วิธีการชำระเงิน</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>ธนาคารกรุงเทพ</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>ภาษีมูลค่าเพิ่ม 7%</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>ยอดสุทธิที่ธนาคารกรุงเทพรับ</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Difference</b></td>";
                    _html += "</tr>";
                }
                else if (ddlLanguage.Text == "2")
                {
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        if (ddlProvider.Text == "0")
                        {
                            _html += "<tr><td align='left' colspan='31' style='font-size:20px; background-color:#D8D8D8;'><b>Sales Summary (" + ReportMonth + ")</b></td></tr>";
                        }
                        else
                        {
                            _html += "<tr><td align='left' colspan='31' style='font-size:20px; background-color:#D8D8D8;'><b>Sales Summary (" + ReportMonth + ") - " + GetProviderName(Convert.ToInt64(ddlProvider.Text), ddlLanguage.Text) + "</b></td></tr>";
                        }
                    }
                    else
                    {
                        if (ddlProvider.Text == "0")
                        {
                            _html += "<tr><td align='left' colspan='30' style='font-size:20px; background-color:#D8D8D8;'><b>Sales Summary (" + ReportMonth + ")</b></td></tr>";
                        }
                        else
                        {
                            _html += "<tr><td align='left' colspan='30' style='font-size:20px; background-color:#D8D8D8;'><b>Sales Summary (" + ReportMonth + ") - " + GetProviderName(Convert.ToInt64(ddlProvider.Text), ddlLanguage.Text) + "</b></td></tr>";
                        }
                    }
                    _html += "<tr>";
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        _html += "<td colspan='6'>&nbsp;</td>";
                    }
                    else
                    {
                        _html += "<td colspan='5'>&nbsp;</td>";
                    }
                    _html += "<td colspan='7' align='center' style='background-color:#fffe97;'><b>Voluntary</b></td>";
                    _html += "<td colspan='6' align='center' style='background-color:#cbffce;'><b>Compulsory</b></td>";
                    _html += "<td colspan='5'>&nbsp;</td>";
                    _html += "<td colspan='6' align='center' style='background-color:#c9ffff;'><b>Bank Statement</b></td>";
                    _html += "</tr>";
                    _html += "<tr>";
                    _html += "<td width='80' align='left' style='font-size:14px; background-color:#81BEF7;'><b>Order Date</b></td>";
                    _html += "<td width='90' align='left' style='font-size:14px; background-color:#81BEF7;'><b>Reference No</b></td>";
                    _html += "<td width='110' align='left' style='font-size:14px; background-color:#81BEF7;'><b>Customer Type</b></td>";
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        _html += "<td width='200' align='left' style='font-size:14px; background-color:#81BEF7;'><b>Application Name</b></td>";
                    }
                    _html += "<td width='70' align='left' style='font-size:14px; background-color:#81BEF7;'><b>Insurer</b></td>";
                    _html += "<td width='100' align='left' style='font-size:14px; background-color:#81BEF7;'><b>Insurance Type</b></td>";
                    _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Policy Start Date</b></td>";
                    _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Policy End Date</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Sales Premium</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Gross Premium</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Net Premium</b></td>";
                    _html += "<td width='60' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Duty</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>VAT</b></td>";
                    _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Policy Start Date</b></td>";
                    _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Policy End Date</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Net Premium</b></td>";
                    _html += "<td width='60' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Duty</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>VAT</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Gross Premium</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Collected Premium</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Discount to Customer</b></td>";
                    _html += "<td width='70' align='left' style='font-size:14px; background-color:#81BEF7;'><b>Discount</b></td>";
                    _html += "<td width='130' align='left' style='font-size:14px; background-color:#81BEF7;'><b>Agent</b></td>";
                    _html += "<td width='200' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Remark</b></td>";
                    _html += "<td width='80' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Premium Receiving Date</b></td>";
                    _html += "<td width='60' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Bank</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Method of Payment</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>BBL Bank Charge</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>VAT 7%</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>BBL Net Received</b></td>";
                    _html += "<td width='100' align='center' style='font-size:14px; background-color:#81BEF7;'><b>Difference</b></td>";
                    _html += "</tr>";
                }
                for (int j = 0; j < TotalFileCount; j++)
                {
                    _html += "<tr>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + OrderDate[j].ToString() + "</td>";
                    _html += "<td width='90' align='left'>" + QuoteRefNo[j].ToString() + "</td>";
                    _html += "<td width='110' align='left'>" + CustomerType[j].ToString() + "</td>";
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        _html += "<td width='200' align='left'>" + ApplicationName[j].ToString() + "</td>";
                    }
                    _html += "<td width='70' align='left'>" + Insurer[j].ToString() + "</td>";
                    _html += "<td width='100' align='left'>" + InsuranceType[j].ToString() + "</td>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + PolicyStartDate[j].ToString() + "</td>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + PolicyEndDate[j].ToString() + "</td>";
                    _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + SalesPremium[j].ToString() + "</td>";
                    _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + GrossPremium[j].ToString() + "</td>";
                    _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + NetPremium[j].ToString() + "</td>";
                    _html += "<td width='60' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + Duty[j].ToString() + "</td>";
                    _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + VAT[j].ToString() + "</td>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + CPolicyStartDate[j].ToString() + "</td>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + CPolicyEndDate[j].ToString() + "</td>";
                    if (IsCTPL[j].ToString().ToUpper() == "YES")
                    {
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + CNetPremium[j].ToString() + "</td>";
                        _html += "<td width='60' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + CDuty[j].ToString() + "</td>";
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + CVAT[j].ToString() + "</td>";
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + CGrossPremium[j].ToString() + "</td>";
                    }
                    else
                    {
                        _html += "<td width='100' align='left'>" + CNetPremium[j].ToString() + "</td>";
                        _html += "<td width='60' align='left'>" + CDuty[j].ToString() + "</td>";
                        _html += "<td width='100' align='left'>" + CVAT[j].ToString() + "</td>";
                        _html += "<td width='100' align='left'>" + CGrossPremium[j].ToString() + "</td>";
                    }
                    _html += "<td width='100' align='right' style='background-color:#fffe97; mso-number-format:\\#\\,\\#\\#0\\.00'>" + CollectedPremium[j].ToString() + "</td>";
                    _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + DiscounttoCustomer[j].ToString() + "</td>";
                    _html += "<td width='70' align='left'>" + Discount[j].ToString() + "</td>";
                    _html += "<td width='130' align='left'>" + Agent[j].ToString() + "</td>";
                    _html += "<td width='200' align='left'>" + Remark[j].ToString() + "</td>";
                    if (PremiumReceivingDate[j].ToString() == string.Empty)
                    {
                        _html += "<td width='80' align='left'>" + PremiumReceivingDate[j].ToString() + "</td>";
                    }
                    else
                    {
                        _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy'>" + PremiumReceivingDate[j].ToString() + "</td>";
                    }
                    _html += "<td width='60' align='left'>" + Bank[j].ToString() + "</td>";
                    _html += "<td width='100' align='left'>" + MethodofPayment[j].ToString() + "</td>";
                    if (BBLBankCharge[j].ToString().Trim() != string.Empty && BBLBankCharge[j].ToString().Trim() != "0")
                    {
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + BBLBankCharge[j].ToString() + "</td>";
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + VAT7[j].ToString() + "</td>";
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + BBLNetReceived[j].ToString() + "</td>";
                    }
                    else
                    {
                        _html += "<td width='100' align='right'>" + BBLBankCharge[j].ToString() + "</td>";
                        _html += "<td width='100' align='right'>" + VAT7[j].ToString() + "</td>";
                        _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + BBLNetReceived[j].ToString() + "</td>";
                    }
                    _html += "<td width='100' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + Difference[j].ToString() + "</td>";
                    _html += "</tr>";
                }
                _html += "<tr>";
                if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                {
                    _html += "<td colspan='10' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                }
                else
                {
                    _html += "<td colspan='9' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                }
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalNetPremium.ToString() + "</b></td>";
                _html += "<td colspan='4' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalCNetPremium.ToString() + "</b></td>";
                _html += "<td colspan='3' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalCollectedPremium.ToString() + "</b></td>";
                _html += "<td colspan='7' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalBBLBankCharge.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalVAT7.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalBBLNetReceived.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + TotalDifference.ToString() + "</b></td>";
                _html += "</tr>";

                _html += "</table>";

                _html += "<table width='20%' cellpadding='1' cellspacing='1'>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "</table>";

                //OIC
                _html += "<table width='25%' cellpadding='1' cellspacing='1' border='1'>";
                if (ddlLanguage.Text == "1")
                {
                    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>รายงานโอไอซีเกี่ยวกับค่านายหน้า</b></td></tr>";
                    _html += "<tr>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บริษัทประกันภัย</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>สมัครใจ</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บังคับ</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>ยอดรวมทั้งหมด</b></td>";
                    _html += "</tr>";
                }
                else if (ddlLanguage.Text == "2")
                {
                    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>OIC Reporting on Brokerage Fee</b></td></tr>";
                    _html += "<tr>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Insurer</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Voluntary</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Compulsory</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Total</b></td>";
                    _html += "</tr>";
                }

                for (int b = 0; b < 15; b++)
                {
                    _html += "<tr>";
                    _html += "<td align='center'><b>" + OICInsurer[b].ToString() + "</b></td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICVoluntary[b].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICCompulsory[b].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICTotal[b].ToString() + "</td>";
                    _html += "</tr>";
                }

                _html += "<tr>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100;'><b>&nbsp;</b></td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICVoluntaryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICCompulsoryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICFinalTotal.ToString() + "</td>";
                _html += "</tr>";

                _html += "</table>";

                _html += "<table width='25%' cellpadding='1' cellspacing='1'>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "</table>";

                //Internal
                _html += "<table width='20%' cellpadding='1' cellspacing='1' border='1'>";
                if (ddlLanguage.Text == "1")
                {
                    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>รายงานภายในเกี่ยวกับค่านายหน้า</b></td></tr>";
                    _html += "<tr>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บริษัทประกันภัย</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>สมัครใจ</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บังคับ</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>ยอดรวมทั้งหมด</b></td>";
                    _html += "</tr>";
                }
                else if (ddlLanguage.Text == "2")
                {
                    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>Internal Reporting on Brokerage Fee</b></td></tr>";
                    _html += "<tr>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Insurer</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Voluntary</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Compulsory</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Total</b></td>";
                    _html += "</tr>";
                }

                for (int c = 0; c < 15; c++)
                {
                    _html += "<tr>";
                    _html += "<td align='center'><b>" + IntInsurer[c].ToString() + "</b></td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntVoluntary[c].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntCompulsory[c].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntTotal[c].ToString() + "</td>";
                    _html += "</tr>";
                }

                _html += "<tr>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100;'><b>&nbsp;</b></td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntVoluntaryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntCompulsoryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntFinalTotal.ToString() + "</td>";
                _html += "</tr>";

                _html += "</table>";

                _html += "<table width='25%' cellpadding='1' cellspacing='1'>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "</table>";

                //Marketing
                _html += "<table width='20%' cellpadding='1' cellspacing='1' border='1'>";
                if (ddlLanguage.Text == "1")
                {
                    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>รายงานภายในเกี่ยวกับค่าการตลาด</b></td></tr>";
                    _html += "<tr>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บริษัทประกันภัย</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>สมัครใจ</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บังคับ</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>ยอดรวมทั้งหมด</b></td>";
                    _html += "</tr>";
                }
                else if (ddlLanguage.Text == "2")
                {
                    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>Internal Reporting on Marketing Fee</b></td></tr>";
                    _html += "<tr>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Insurer</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Voluntary</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Compulsory</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Total</b></td>";
                    _html += "</tr>";
                }

                for (int d = 0; d < 15; d++)
                {
                    _html += "<tr>";
                    _html += "<td align='center'><b>" + MktInsurer[d].ToString() + "</b></td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktVoluntary[d].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktCompulsory[d].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktTotal[d].ToString() + "</td>";
                    _html += "</tr>";
                }

                _html += "<tr>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100;'><b>&nbsp;</b></td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktVoluntaryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktCompulsoryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktFinalTotal.ToString() + "</td>";
                _html += "</tr>";

                _html += "</table>";
                _html += "</body>";
                _html += "</html>";
                #endregion

                lblContent.Text = _html;
                ExportGridView(_fileName, lblContent);
            }
        }
    }

    public void GenerateExcel()
    {
        string _html = "";
        string _fileName = "AgentSales@" + CE.Global.General.GetUTCDateTime().Day.ToString("00") + "-" + CE.Global.General.GetUTCDateTime().Month.ToString("00") + "-" + CE.Global.General.GetUTCDateTime().Year;
        lblContent.Text = "";
        lblError.Text = "";
        if (Validatioin() == true)
        {
            txtReportDate1.Text = "";
            txtReportDate2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000") + CE.Global.General.GetUTCDateTime().Month.ToString("00") + CE.Global.General.GetUTCDateTime().Day.ToString("00");
            txtReportDate1.Text = ddlYear1.Text;
            txtReportDate1.Text += ddlMonth1.Text;
            txtReportDate1.Text += ddlDay1.Text;
            if (Convert.ToInt16(ddlReportType.Text) == 0)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 1)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += ddlDay1.Text;
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 2)
            {
                txtReportDate2.Text = ddlYear2.Text;
                txtReportDate2.Text += ddlMonth2.Text;
                txtReportDate2.Text += ddlDay2.Text;
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 3)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += "01";
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 4)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += "16";
            }


            Int32 OnlineCount = 0;
            Int32 OfflineCount = 0;
            Int32 TotalFileCount = 0;
            Int32 TotalCMIFileCount = 0;
            DataSet _dsSummary = new DataSet();
            DataTable _dtSummary = new DataTable();
            DataTable _dtCMISummary = new DataTable();
            Int16 _ReportType = Convert.ToInt16(ddlReportType.Text);
            string _ReportDate1 = txtReportDate1.Text.Trim();
            string _ReportDate2 = txtReportDate2.Text.Trim();
            Int32 _UserTypeId = Convert.ToInt32(ddlCampaign.Text);

            MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
            string _spName = "[sprocCXCRMAgentSalesSummarySelectedList]";
            SortedList _sPara = new SortedList();

            _sPara.Add("@ReportType", _ReportType);
            _sPara.Add("@ReportDate1", _ReportDate1);
            _sPara.Add("@ReportDate2", _ReportDate2);
            _sPara.Add("@Insurer", Convert.ToInt64(ddlProvider.Text));
            if (Convert.ToInt64(Session[General.UserId].ToString()) == 14)
            {
                _sPara.Add("@IsAgentOnly", 1);
            }
            else
            {
                _sPara.Add("@IsAgentOnly", Convert.ToInt16(ddlSeller.Text));
            }
            _sPara.Add("@UserTypeId", _UserTypeId);

            _dsSummary = _db.GetDataSet(_spName, _sPara);
            if (_dsSummary != null && _dsSummary.Tables.Count > 0 && _dsSummary.Tables[0].Rows.Count > 0)
            {
                _dtSummary = _dsSummary.Tables[0];
                TotalFileCount += _dtSummary.Rows.Count;
            }
            if (_dsSummary != null && _dsSummary.Tables.Count > 3 && _dsSummary.Tables[3].Rows.Count > 0)
            {
                _dtCMISummary = _dsSummary.Tables[3];
                TotalCMIFileCount += _dtCMISummary.Rows.Count;
            }
            if (TotalFileCount > 0)
            {
                #region Variable Declaration
                string PaymentType = "";

                string[] CECarId = new string[TotalFileCount];
                string[] ProviderCompanyId = new string[TotalFileCount];
                string[] OrderDate = new string[TotalFileCount];
                string[] TypeOfLeads = new string[TotalFileCount];
                string[] ApplicationName = new string[TotalFileCount];
                string[] Insurer = new string[TotalFileCount];
                string[] InsuranceType = new string[TotalFileCount];
                string[] PolicyStartDate = new string[TotalFileCount];
                string[] PolicyEndDate = new string[TotalFileCount];
                string[] GrossPremium = new string[TotalFileCount];
                string[] NetPremium = new string[TotalFileCount];
                string[] Duty = new string[TotalFileCount];
                string[] VAT = new string[TotalFileCount];
                string[] BrokageFee = new string[TotalFileCount];
                string[] MarketingFee = new string[TotalFileCount];
                string[] CollectedPremium = new string[TotalFileCount];
                string[] DiscounttoCustomer = new string[TotalFileCount];
                string[] Discount = new string[TotalFileCount];
                string[] PremiumReceivingDate = new string[TotalFileCount];
                string[] Agent = new string[TotalFileCount];
                string[] MethodofPayment = new string[TotalFileCount];
                string[] OfflineRenewComm = new string[TotalFileCount];
                string[] Remark = new string[TotalFileCount];
                string[] Print = new string[TotalFileCount];
                string[] Bank = new string[TotalFileCount];
                string[] CarPlate = new string[TotalFileCount];
                string[] QuoteRefNo = new string[TotalFileCount];

                string[] CMICECarId = new string[TotalCMIFileCount];
                string[] CMIProviderCompanyId = new string[TotalCMIFileCount];
                string[] CMIOrderDate = new string[TotalCMIFileCount];
                string[] CMITypeOfLeads = new string[TotalCMIFileCount];
                string[] CMIApplicationName = new string[TotalCMIFileCount];
                string[] CMIInsurer = new string[TotalCMIFileCount];
                string[] CMIInsuranceType = new string[TotalCMIFileCount];
                string[] CMIPolicyStartDate = new string[TotalCMIFileCount];
                string[] CMIPolicyEndDate = new string[TotalCMIFileCount];
                string[] CMIGrossPremium = new string[TotalCMIFileCount];
                string[] CMINetPremium = new string[TotalCMIFileCount];
                string[] CMIDuty = new string[TotalCMIFileCount];
                string[] CMIVAT = new string[TotalCMIFileCount];
                string[] CMIBrokageFee = new string[TotalCMIFileCount];
                string[] CMIMarketingFee = new string[TotalCMIFileCount];
                string[] CMICollectedPremium = new string[TotalCMIFileCount];
                string[] CMIDiscounttoCustomer = new string[TotalCMIFileCount];
                string[] CMIDiscount = new string[TotalCMIFileCount];
                string[] CMIPremiumReceivingDate = new string[TotalCMIFileCount];
                string[] CMIAgent = new string[TotalCMIFileCount];
                string[] CMIMethodofPayment = new string[TotalCMIFileCount];
                string[] CMIOfflineRenewComm = new string[TotalCMIFileCount];
                string[] CMIRemark = new string[TotalCMIFileCount];
                string[] CMIPrint = new string[TotalCMIFileCount];
                string[] CMIBank = new string[TotalCMIFileCount];
                string[] CMICarPlate = new string[TotalCMIFileCount];
                string[] CMIQuoteRefNo = new string[TotalCMIFileCount];

                string[] IsCTPL = new string[TotalFileCount];
                string[] CTPL = new string[TotalFileCount];
                string[] GarageType = new string[TotalFileCount];
                string[] InsuranceTypeId = new string[TotalFileCount];


                decimal dec_GrossPremium, dec_CollectedPreium, dec_NetPremium, dec_Discount, dec_DiscountPercent;
                decimal dec_VAT, dec_Duty, dec_Brokerage, dec_Marketing;
                decimal dec_CMIGrossPremium, dec_CMICollectedPreium, dec_CMINetPremium, dec_CMIDiscount, dec_CMIDiscountPercent;
                decimal dec_CMIVAT, dec_CMIDuty, dec_CMIBrokerage, dec_CMIMarketing;

                decimal dec_TotalGrossPremium, dec_TotalCollectedPreium, dec_TotalNetPremium, dec_TotalDiscount;
                decimal dec_TotalVAT, dec_TotalDuty, dec_TotalBrokerage, dec_TotalMarketing;
                #endregion

                #region Value Assign
                dec_TotalGrossPremium = 0; dec_TotalCollectedPreium = 0; dec_TotalNetPremium = 0; dec_TotalDiscount = 0;
                dec_TotalVAT = 0; dec_TotalDuty = 0; dec_TotalBrokerage = 0; dec_TotalMarketing = 0;
                for (int i = 0; i < TotalFileCount; i++)
                {
                    dec_GrossPremium = 0; dec_CollectedPreium = 0; dec_NetPremium = 0; dec_Discount = 0; dec_DiscountPercent = 0;
                    dec_VAT = 0; dec_Duty = 0; dec_Brokerage = 0; dec_Marketing = 0; 
                
                    CECarId[i] = _dtSummary.Rows[i]["CECarId"].ToString();
                    ProviderCompanyId[i] = _dtSummary.Rows[i]["ProviderCompanyId"].ToString();
                    IsCTPL[i] = _dtSummary.Rows[i]["IsCTPL"].ToString();
                    CTPL[i] = _dtSummary.Rows[i]["CTPL"].ToString();
                    GarageType[i] = _dtSummary.Rows[i]["GarageType"].ToString();

                    OrderDate[i] = _dtSummary.Rows[i]["OrderDate"].ToString();
                    TypeOfLeads[i] = _dtSummary.Rows[i]["TypeOfLeads"].ToString();
                    ApplicationName[i] = _dtSummary.Rows[i]["ApplicationName"].ToString();
                    Insurer[i] = _dtSummary.Rows[i]["Insurer"].ToString();
                    InsuranceType[i] = _dtSummary.Rows[i]["InsuranceType"].ToString();
                    PolicyStartDate[i] = _dtSummary.Rows[i]["PolicyStartDate"].ToString();
                    PolicyEndDate[i] = _dtSummary.Rows[i]["PolicyEndDate"].ToString();
                    GrossPremium[i] = _dtSummary.Rows[i]["GrossPremium"].ToString();
                    NetPremium[i] = _dtSummary.Rows[i]["NetPremium"].ToString();
                    Duty[i] = _dtSummary.Rows[i]["Duty"].ToString();
                    VAT[i] = _dtSummary.Rows[i]["VAT"].ToString();
                    BrokageFee[i] = _dtSummary.Rows[i]["BrokageFee"].ToString();
                    MarketingFee[i] = _dtSummary.Rows[i]["MarketingFee"].ToString();
                    CollectedPremium[i] = _dtSummary.Rows[i]["ApprovedPremium"].ToString();

                    if (!decimal.TryParse(GrossPremium[i].ToString(), out dec_GrossPremium))
                    {
                        dec_GrossPremium = 0;
                    }
                    if (!decimal.TryParse(NetPremium[i].ToString(), out dec_NetPremium))
                    {
                        dec_NetPremium = 0;
                    }
                    if (!decimal.TryParse(Duty[i].ToString(), out dec_Duty))
                    {
                        dec_Duty = 0;
                    }
                    if (!decimal.TryParse(VAT[i].ToString(), out dec_VAT))
                    {
                        dec_VAT = 0;
                    }
                    if (!decimal.TryParse(BrokageFee[i].ToString(), out dec_Brokerage))
                    {
                        dec_Brokerage = 0;
                    }
                    if (!decimal.TryParse(MarketingFee[i].ToString(), out dec_Marketing))
                    {
                        dec_Marketing = 0;
                    }
                    if (!decimal.TryParse(CollectedPremium[i].ToString(), out dec_CollectedPreium))
                    {
                        dec_CollectedPreium = 0;
                    }
                    if (dec_GrossPremium > 0 && dec_CollectedPreium > 0)
                    {
                        dec_Discount = (dec_GrossPremium - dec_CollectedPreium);
                    }
                    if (dec_NetPremium > 0 && dec_Discount > 0)
                    {
                        dec_DiscountPercent = (dec_Discount / dec_NetPremium) * 100;
                    }

                    DiscounttoCustomer[i] = dec_Discount.ToString("#0.00");
                    Discount[i] = dec_DiscountPercent.ToString("#0.00") + "%";
                    PremiumReceivingDate[i] = _dtSummary.Rows[i]["OrderDate"].ToString();
                    if (ddlLanguage.Visible == false)
                    {
                        Agent[i] = _dtSummary.Rows[i]["AgentName"].ToString();
                    }
                    else if (ddlLanguage.Text == "1")
                    {
                        Agent[i] = _dtSummary.Rows[i]["AgentName"].ToString();
                    }
                    else if (ddlLanguage.Text == "2")
                    {
                        Agent[i] = _dtSummary.Rows[i]["AgentNameEN"].ToString();
                    }
                    OfflineRenewComm[i] = " ";
                    Remark[i] = _dtSummary.Rows[i]["Remarks"].ToString();
                    Print[i] = " ";
                    CarPlate[i] = _dtSummary.Rows[i]["CarPlate"].ToString();
                    QuoteRefNo[i] = _dtSummary.Rows[i]["QuoteRefNo"].ToString();

                    dec_TotalGrossPremium += dec_GrossPremium;
                    dec_TotalNetPremium += dec_NetPremium;
                    dec_TotalDuty += dec_Duty;
                    dec_TotalVAT += dec_VAT;
                    dec_TotalBrokerage += dec_Brokerage;
                    dec_TotalMarketing += dec_Marketing;
                    dec_TotalCollectedPreium += dec_CollectedPreium;
                    dec_TotalDiscount += dec_Discount;
                    Bank[i] = "BBL";
                    MethodofPayment[i] = " ";
                    if (_dsSummary != null && _dsSummary.Tables.Count > 1 && _dsSummary.Tables[1].Rows.Count > 0)
                    {
                        string _PayDetails = GetPaymentDetailListNew(Convert.ToInt64(CECarId[i].ToString()), Convert.ToInt64(ProviderCompanyId[i].ToString()));
                        string[] _PayDetail = _PayDetails.Split('@');
                        if (_PayDetail.Length > 0)
                        {
                            MethodofPayment[i] = _PayDetail[0].ToString();
                        }
                        if (_PayDetail.Length > 1)
                        {
                            Bank[i] = _PayDetail[1].ToString();
                        }
                    }
                }
                #endregion

                #region CMI Value Assign
                if (TotalCMIFileCount > 0)
                {
                    for (int j = 0; j < TotalCMIFileCount; j++)
                    {
                        dec_CMIGrossPremium = 0; dec_CMICollectedPreium = 0; dec_CMINetPremium = 0; dec_CMIDiscount = 0; dec_CMIDiscountPercent = 0;
                        dec_CMIVAT = 0; dec_CMIDuty = 0; dec_CMIBrokerage = 0; dec_CMIMarketing = 0;

                        CMICECarId[j] = _dtCMISummary.Rows[j]["CECarId"].ToString();
                        CMIProviderCompanyId[j] = _dtCMISummary.Rows[j]["ProviderCompanyId"].ToString();

                        CMIOrderDate[j] = _dtCMISummary.Rows[j]["OrderDate"].ToString();
                        CMITypeOfLeads[j] = _dtCMISummary.Rows[j]["TypeOfLeads"].ToString();
                        CMIApplicationName[j] = _dtCMISummary.Rows[j]["ApplicationName"].ToString();
                        CMIInsurer[j] = _dtCMISummary.Rows[j]["Insurer"].ToString();
                        CMIInsuranceType[j] = _dtCMISummary.Rows[j]["InsuranceType"].ToString();
                        CMIPolicyStartDate[j] = _dtCMISummary.Rows[j]["PolicyStartDate"].ToString();
                        CMIPolicyEndDate[j] = _dtCMISummary.Rows[j]["PolicyEndDate"].ToString();
                        CMIGrossPremium[j] = _dtCMISummary.Rows[j]["GrossPremium"].ToString();
                        CMINetPremium[j] = _dtCMISummary.Rows[j]["NetPremium"].ToString();
                        CMIDuty[j] = _dtCMISummary.Rows[j]["Duty"].ToString();
                        CMIVAT[j] = _dtCMISummary.Rows[j]["VAT"].ToString();
                        CMIBrokageFee[j] = _dtCMISummary.Rows[j]["BrokageFee"].ToString();
                        CMIMarketingFee[j] = _dtCMISummary.Rows[j]["MarketingFee"].ToString();
                        CMICollectedPremium[j] = _dtCMISummary.Rows[j]["ApprovedPremium"].ToString();

                        if (!decimal.TryParse(CMIGrossPremium[j].ToString(), out dec_CMIGrossPremium))
                        {
                            dec_CMIGrossPremium = 0;
                        }
                        if (!decimal.TryParse(CMINetPremium[j].ToString(), out dec_CMINetPremium))
                        {
                            dec_CMINetPremium = 0;
                        }
                        if (!decimal.TryParse(CMIDuty[j].ToString(), out dec_CMIDuty))
                        {
                            dec_CMIDuty = 0;
                        }
                        if (!decimal.TryParse(CMIVAT[j].ToString(), out dec_CMIVAT))
                        {
                            dec_CMIVAT = 0;
                        }
                        if (!decimal.TryParse(CMIBrokageFee[j].ToString(), out dec_CMIBrokerage))
                        {
                            dec_CMIBrokerage = 0;
                        }
                        if (!decimal.TryParse(CMIMarketingFee[j].ToString(), out dec_CMIMarketing))
                        {
                            dec_CMIMarketing = 0;
                        }
                        if (!decimal.TryParse(CMICollectedPremium[j].ToString(), out dec_CMICollectedPreium))
                        {
                            dec_CMICollectedPreium = 0;
                        }
                        if (dec_CMIGrossPremium > 0 && dec_CMICollectedPreium > 0)
                        {
                            dec_CMIDiscount = (dec_CMIGrossPremium - dec_CMICollectedPreium);
                        }
                        if (dec_CMINetPremium > 0 && dec_CMIDiscount > 0)
                        {
                            dec_CMIDiscountPercent = (dec_CMIDiscount / dec_CMINetPremium) * 100;
                        }

                        CMIDiscounttoCustomer[j] = dec_CMIDiscount.ToString("#0.00");
                        CMIDiscount[j] = dec_CMIDiscountPercent.ToString("#0.00") + "%";
                        CMIPremiumReceivingDate[j] = _dtSummary.Rows[j]["OrderDate"].ToString();                        
                        if (ddlLanguage.Visible == false)
                        {
                            CMIAgent[j] = _dtCMISummary.Rows[j]["AgentName"].ToString();
                        }
                        else if (ddlLanguage.Text == "1")
                        {
                            CMIAgent[j] = _dtCMISummary.Rows[j]["AgentName"].ToString();
                        }
                        else if (ddlLanguage.Text == "2")
                        {
                            CMIAgent[j] = _dtCMISummary.Rows[j]["AgentNameEN"].ToString();
                        }
                        CMIOfflineRenewComm[j] = " ";
                        CMIRemark[j] = _dtCMISummary.Rows[j]["Remarks"].ToString();
                        CMIPrint[j] = " ";
                        CMICarPlate[j] = _dtCMISummary.Rows[j]["CarPlate"].ToString();
                        CMIQuoteRefNo[j] = _dtCMISummary.Rows[j]["QuoteRefNo"].ToString();


                        dec_TotalGrossPremium += dec_CMIGrossPremium;
                        dec_TotalNetPremium += dec_CMINetPremium;
                        dec_TotalDuty += dec_CMIDuty;
                        dec_TotalVAT += dec_CMIVAT;
                        dec_TotalBrokerage += dec_CMIBrokerage;
                        dec_TotalMarketing += dec_CMIMarketing;
                        dec_TotalCollectedPreium += dec_CMICollectedPreium;
                        dec_TotalDiscount += dec_CMIDiscount;
                        CMIBank[j] = "BBL";
                        CMIMethodofPayment[j] = " ";
                        if (_dsSummary != null && _dsSummary.Tables.Count > 1 && _dsSummary.Tables[1].Rows.Count > 0)
                        {
                            string _CMIPayDetails = GetPaymentDetailListNew(Convert.ToInt64(CMICECarId[j].ToString()), Convert.ToInt64(CMIProviderCompanyId[j].ToString()));
                            string[] _CMIPayDetail = _CMIPayDetails.Split('@');
                            if (_CMIPayDetail.Length > 0)
                            {
                                CMIMethodofPayment[j] = _CMIPayDetail[0].ToString();
                            }
                            if (_CMIPayDetail.Length > 1)
                            {
                                CMIBank[j] = _CMIPayDetail[1].ToString();
                            }
                        }
                    }
                }
                #endregion

                #region Generate Excel
                string ReportMonth = "";
                if (_ReportType == 0)
                {
                    ReportMonth = GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                }
                else if (_ReportType == 1)
                {
                    ReportMonth = ddlDay1.Text + " " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                }
                else if (_ReportType == 3)
                {
                    ReportMonth = "01 " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text + " TO 15 " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                }
                else if (_ReportType == 4)
                {
                    ReportMonth = "16 " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text + " TO " + LastDayOfMonth("16/" + ddlMonth1.Text + "/" + ddlYear1.Text) + " " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                }
                _html += "<html>";
                _html += "<head>";
                _html += "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>";
                _html += "</head>";
                _html += "<body>";
                _html += "<table width='100%' cellpadding='1' cellspacing='1' border='1'>";
                
                if (ddlLanguage.Text == "1")
                {
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        if (ddlProvider.Text == "0")
                        {
                            _html += "<tr><td align='left' colspan='25' style='font-size:20px; background-color:#D8C7FF;'><b>ยอดขายรวม (" + ReportMonth + ")</b></td></tr>";
                        }
                        else
                        {
                            _html += "<tr><td align='left' colspan='25' style='font-size:20px; background-color:#D8C7FF;'><b>ยอดขายรวม (" + ReportMonth + ") - " + GetProviderName(Convert.ToInt64(ddlProvider.Text), ddlLanguage.Text) + "</b></td></tr>";
                        }
                    }
                    else
                    {
                        if (ddlProvider.Text == "0")
                        {
                            _html += "<tr><td align='left' colspan='24' style='font-size:20px; background-color:#D8C7FF;'><b>ยอดขายรวม (" + ReportMonth + ")</b></td></tr>";
                        }
                        else
                        {
                            _html += "<tr><td align='left' colspan='24' style='font-size:20px; background-color:#D8C7FF;'><b>ยอดขายรวม (" + ReportMonth + ") - " + GetProviderName(Convert.ToInt64(ddlProvider.Text), ddlLanguage.Text) + "</b></td></tr>";
                        }
                    }
                    _html += "<tr>";
                    _html += "<td width='80' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>วันที่ทำรายการ</b></td>";
                    _html += "<td width='80' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>ประเภทลูกค้า</b></td>";
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        _html += "<td width='200' height='30' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>ชื่อผู้สมัคร</b></td>";
                    }
                    _html += "<td width='80' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>บริษัทประกันภัย</b></td>";
                    _html += "<td width='80' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>ประเภทประกันภัย</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>วันเริ่มความคุ้มครอง</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>วันสิ้นสุดกรมธรรม์</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>ยอดรวมเบี้ยประกันภัย</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>เบี้ยประกันภัย</b></td>";
                    _html += "<td width='60' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>อากร</b></td>";
                    _html += "<td width='60' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>ภาษีมูลค่าเพิ่ม</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>ค่าส่งเสริมการขาย</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>ค่าการตลาด</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>เบี้ยประกันภัยที่เรียกเก็บ</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>ลดราคาสำหรับลูกค้า</b></td>";
                    _html += "<td width='70' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>ส่วนลด</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>วันที่รับเบี้ยประกัน</b></td>";
                    _html += "<td width='120' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>เอเย่นต์</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>วิธีการชำระเงิน</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>ค่าคอมมิชชั่นลูกค้า offline และ Renew</b></td>";
                    _html += "<td width='200' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>หมายเหต</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#FFFF9E;'><b>ปริ้นกรมธรรม์</b></td>";
                    _html += "<td width='60' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#5858FA; color:#FFFFFF;'><b>ธนาคาร</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#BC65FF;'><b>ทะเบียนรถยนต์</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#FFFF00;'><b>เลขที่อ้างอืง</b></td>";
                    _html += "</tr>";
                }
                else if (ddlLanguage.Text == "2")
                {
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        if (ddlProvider.Text == "0")
                        {
                            _html += "<tr><td align='left' colspan='25' style='font-size:20px; background-color:#D8C7FF;'><b>Sales Summary (" + ReportMonth + ")</b></td></tr>";
                        }
                        else
                        {
                            _html += "<tr><td align='left' colspan='25' style='font-size:20px; background-color:#D8C7FF;'><b>Sales Summary (" + ReportMonth + ") - " + GetProviderName(Convert.ToInt64(ddlProvider.Text), ddlLanguage.Text) + "</b></td></tr>";
                        }
                    }
                    else
                    {
                        if (ddlProvider.Text == "0")
                        {
                            _html += "<tr><td align='left' colspan='24' style='font-size:20px; background-color:#D8C7FF;'><b>Sales Summary (" + ReportMonth + ")</b></td></tr>";
                        }
                        else
                        {
                            _html += "<tr><td align='left' colspan='24' style='font-size:20px; background-color:#D8C7FF;'><b>Sales Summary (" + ReportMonth + ") - " + GetProviderName(Convert.ToInt64(ddlProvider.Text), ddlLanguage.Text) + "</b></td></tr>";
                        }
                    }
                    _html += "<tr>";
                    _html += "<td width='80' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Order Date</b></td>";
                    _html += "<td width='80' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Type of Leads</b></td>";
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        _html += "<td width='200' height='30' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Application Name</b></td>";
                    }
                    _html += "<td width='80' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Insurer</b></td>";
                    _html += "<td width='80' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Insurance Type</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Policy Start Date</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Policy End Date</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Gross Premium</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Net Premium</b></td>";
                    _html += "<td width='60' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Duty</b></td>";
                    _html += "<td width='60' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>VAT</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Brokerage Fee</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Marketing Fee</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Collected Premium</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Discount to Customer</b></td>";
                    _html += "<td width='70' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Discount</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Premium Receiving Date</b></td>";
                    _html += "<td width='120' height='40' style='text-align: left; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Agent</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Method of Payment</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Offline/Renew Comm</b></td>";
                    _html += "<td width='200' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#808080; color:#FFFFFF;'><b>Remark</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#FFFF9E;'><b>Print</b></td>";
                    _html += "<td width='60' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#5858FA; color:#FFFFFF;'><b>Bank</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#BC65FF;'><b>Car Plate</b></td>";
                    _html += "<td width='80' height='40' style='text-align: center; vertical-align:middle; font-size:14px; background-color:#FFFF00;'><b>Reference No.</b></td>";
                    _html += "</tr>";
                }
                for (int j = 0; j < TotalFileCount; j++)
                {
                    _html += "<tr>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + OrderDate[j].ToString() + "</td>";
                    _html += "<td width='80' align='left'>" + TypeOfLeads[j].ToString() + "</td>";
                    if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                    {
                        _html += "<td width='200' align='left'>" + ApplicationName[j].ToString() + "</td>";
                    }
                    _html += "<td width='70' align='left'>" + Insurer[j].ToString() + "</td>";
                    _html += "<td width='80' align='left'>" + InsuranceType[j].ToString() + "</td>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + PolicyStartDate[j].ToString() + "</td>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + PolicyEndDate[j].ToString() + "</td>";
                    _html += "<td width='80' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + GrossPremium[j].ToString() + "</td>";
                    _html += "<td width='80' align='right' style='background-color:#FFFE97; mso-number-format:\\#\\,\\#\\#0\\.00'>" + NetPremium[j].ToString() + "</td>";
                    _html += "<td width='60' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + Duty[j].ToString() + "</td>";
                    _html += "<td width='60' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + VAT[j].ToString() + "</td>";
                    _html += "<td width='80' align='right' style='background-color:#FFCC9A; mso-number-format:\\#\\,\\#\\#0\\.00'>" + BrokageFee[j].ToString() + "</td>";
                    _html += "<td width='80' align='right' style='background-color:#FFCC9A; mso-number-format:\\#\\,\\#\\#0\\.00'>" + MarketingFee[j].ToString() + "</td>";
                    _html += "<td width='80' align='right' style='background-color:#C7FFE6; mso-number-format:\\#\\,\\#\\#0\\.00'>" + CollectedPremium[j].ToString() + "</td>";
                    _html += "<td width='80' align='right' style='background-color:#C7FFE6; mso-number-format:\\#\\,\\#\\#0\\.00'>" + DiscounttoCustomer[j].ToString() + "</td>";
                    _html += "<td width='70' align='right'>" + Discount[j].ToString() + "</td>";
                    _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy'>" + PremiumReceivingDate[j].ToString() + "</td>";
                    _html += "<td width='120' align='left'>" + Agent[j].ToString() + "</td>";
                    _html += "<td width='80' align='left'>" + MethodofPayment[j].ToString() + "</td>";
                    _html += "<td width='80' align='left'>" + OfflineRenewComm[j].ToString() + "</td>";
                    _html += "<td width='200' align='left'>" + Remark[j].ToString() + "</td>";
                    _html += "<td width='80' align='left'>" + Print[j].ToString() + "</td>";
                    _html += "<td width='60' align='left'>" + Bank[j].ToString() + "</td>";
                    _html += "<td width='80' align='left'>" + CarPlate[j].ToString() + "</td>";
                    _html += "<td width='80' align='left'>" + QuoteRefNo[j].ToString() + "</td>";
                    _html += "</tr>";
                }               
                _html += "</table>";

                if (TotalCMIFileCount > 0)
                {
                    _html += "<table width='100%' cellpadding='1' cellspacing='1' border='1'>";
                    if (ddlLanguage.Text == "1")
                    {
                        if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                        {
                            _html += "<tr><td align='left' colspan='25' style='font-size:16px; background-color:#808080; color:#FFFFFF;'><b>บังคับ</b></td></tr>";
                        }
                        else
                        {
                            _html += "<tr><td align='left' colspan='24' style='font-size:16px; background-color:#808080; color:#FFFFFF;'><b>บังคับ</b></td></tr>";
                        }
                    }
                    else if (ddlLanguage.Text == "2")
                    {
                        if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                        {
                            _html += "<tr><td align='left' colspan='25' style='font-size:16px; background-color:#808080; color:#FFFFFF;'><b>Compulsory</b></td></tr>";
                        }
                        else
                        {
                            _html += "<tr><td align='left' colspan='24' style='font-size:16px; background-color:#808080; color:#FFFFFF;'><b>Compulsory</b></td></tr>";
                        }
                    }
                    for (int j = 0; j < TotalCMIFileCount; j++)
                    {
                        _html += "<tr>";
                        _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + OrderDate[j].ToString() + "</td>";
                        _html += "<td width='80' align='left'>" + TypeOfLeads[j].ToString() + "</td>";
                        if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                        {
                            _html += "<td width='200' align='left'>" + CMIApplicationName[j].ToString() + "</td>";
                        }
                        _html += "<td width='70' align='left'>" + CMIInsurer[j].ToString() + "</td>";
                        _html += "<td width='80' align='left'>" + CMIInsuranceType[j].ToString() + "</td>";
                        _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + CMIPolicyStartDate[j].ToString() + "</td>";
                        _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy hh\\:mm tt'>" + CMIPolicyEndDate[j].ToString() + "</td>";
                        _html += "<td width='80' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + CMIGrossPremium[j].ToString() + "</td>";
                        _html += "<td width='80' align='right' style='background-color:#FFFE97; mso-number-format:\\#\\,\\#\\#0\\.00'>" + CMINetPremium[j].ToString() + "</td>";
                        _html += "<td width='60' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + CMIDuty[j].ToString() + "</td>";
                        _html += "<td width='60' align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + CMIVAT[j].ToString() + "</td>";
                        _html += "<td width='80' align='right' style='background-color:#FFCC9A; mso-number-format:\\#\\,\\#\\#0\\.00'>" + CMIBrokageFee[j].ToString() + "</td>";
                        _html += "<td width='80' align='right' style='background-color:#FFCC9A; mso-number-format:\\#\\,\\#\\#0\\.00'>" + CMIMarketingFee[j].ToString() + "</td>";
                        _html += "<td width='80' align='right' style='background-color:#C7FFE6; mso-number-format:\\#\\,\\#\\#0\\.00'>" + CMICollectedPremium[j].ToString() + "</td>";
                        _html += "<td width='80' align='right' style='background-color:#C7FFE6; mso-number-format:\\#\\,\\#\\#0\\.00'>" + CMIDiscounttoCustomer[j].ToString() + "</td>";
                        _html += "<td width='70' align='right'>" + CMIDiscount[j].ToString() + "</td>";
                        _html += "<td width='80' align='left' style='mso-number-format:dd\\-mmm\\-yyyy'>" + CMIPremiumReceivingDate[j].ToString() + "</td>";
                        _html += "<td width='120' align='left'>" + CMIAgent[j].ToString() + "</td>";
                        _html += "<td width='80' align='left'>" + CMIMethodofPayment[j].ToString() + "</td>";
                        _html += "<td width='80' align='left'>" + CMIOfflineRenewComm[j].ToString() + "</td>";
                        _html += "<td width='200' align='left'>" + CMIRemark[j].ToString() + "</td>";
                        _html += "<td width='80' align='left'>" + CMIPrint[j].ToString() + "</td>";
                        _html += "<td width='60' align='left'>" + CMIBank[j].ToString() + "</td>";
                        _html += "<td width='80' align='left'>" + CMICarPlate[j].ToString() + "</td>";
                        _html += "<td width='80' align='left'>" + CMIQuoteRefNo[j].ToString() + "</td>";
                        _html += "</tr>";
                    }
                    _html += "</table>";
                }
                #region Total
                _html += "<table width='100%' cellpadding='1' cellspacing='1' border='1'>";
                _html += "<tr>";
                if (Session[CE.Global.General.UserRole] != null && (Session[CE.Global.General.UserRole].ToString() == "300" || Session[CE.Global.General.UserRole].ToString() == "200"))
                {
                    _html += "<td colspan='7' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                }
                else
                {
                    _html += "<td colspan='6' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                }
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + dec_TotalGrossPremium.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + dec_TotalNetPremium.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + dec_TotalDuty.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + dec_TotalVAT.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + dec_TotalBrokerage.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + dec_TotalMarketing.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + dec_TotalCollectedPreium.ToString() + "</b></td>";
                _html += "<td width='100px' align='right' style='font-size:17px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + dec_TotalDiscount.ToString() + "</b></td>";
                _html += "<td colspan='10' style='font-size:17px; background-color:#FFE100;'>&nbsp;</td>";
                _html += "</tr>";
                _html += "</table>";
                #endregion

                //_html += "<table width='20%' cellpadding='1' cellspacing='1'>";
                //_html += "<tr><td>&nbsp;</td></tr>";
                //_html += "</table>";

                _html += "</body>";
                _html += "</html>";
                #endregion

                lblContent.Text = _html;
                ExportGridView(_fileName, lblContent);
            }
        }
    }

    public void GenerateOICExcel()
    {
        string _html = "";
        string _fileName = "OIC@";
        lblContent.Text = "";
        lblError.Text = "";
        if (Validatioin() == true)
        {
            txtReportDate1.Text = "";
            txtReportDate2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000") + CE.Global.General.GetUTCDateTime().Month.ToString("00") + CE.Global.General.GetUTCDateTime().Day.ToString("00");
            txtReportDate1.Text = ddlYear1.Text;
            txtReportDate1.Text += ddlMonth1.Text;
            txtReportDate1.Text += ddlDay1.Text;
            if (Convert.ToInt16(ddlReportType.Text) == 0)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 1)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += ddlDay1.Text;
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 2)
            {
                txtReportDate2.Text = ddlYear2.Text;
                txtReportDate2.Text += ddlMonth2.Text;
                txtReportDate2.Text += ddlDay2.Text;
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 3)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += "01";
            }
            else if (Convert.ToInt16(ddlReportType.Text) == 4)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += "16";
            }

            Int32 TotalFileCount = 0;
            Int32 TotalCMIFileCount = 0;
            DataSet _dsSummary = new DataSet();
            DataTable _dtSummary = new DataTable();
            DataTable _dtCMISummary = new DataTable();
            Int16 _ReportType = Convert.ToInt16(ddlReportType.Text);
            string _ReportDate1 = txtReportDate1.Text.Trim();
            string _ReportDate2 = txtReportDate2.Text.Trim();
            Int32 _UserTypeId = Convert.ToInt32(ddlCampaign.Text);

            MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
            string _spName = "[sprocCXCRMAgentSalesSummarySelectedList]";
            SortedList _sPara = new SortedList();

            _sPara.Add("@ReportType", _ReportType);
            _sPara.Add("@ReportDate1", _ReportDate1);
            _sPara.Add("@ReportDate2", _ReportDate2);
            _sPara.Add("@Insurer", Convert.ToInt64(ddlProvider.Text));
            if (Convert.ToInt64(Session[General.UserId].ToString()) == 14)
            {
                _sPara.Add("@IsAgentOnly", 1);
            }
            else
            {
                _sPara.Add("@IsAgentOnly", Convert.ToInt16(ddlSeller.Text));
            }
            _sPara.Add("@UserTypeId", _UserTypeId);

            _fileName += GetMonth(txtReportDate.Text.Trim().Substring(4, 2).ToString()).Trim() + txtReportDate.Text.Trim().Substring(0, 4).ToString();
            _dsSummary = _db.GetDataSet(_spName, _sPara);
            if (_dsSummary != null && _dsSummary.Tables.Count > 0 && _dsSummary.Tables[0].Rows.Count > 0)
            {
                _dtSummary = _dsSummary.Tables[0];
                TotalFileCount += _dtSummary.Rows.Count;
            }
            if (_dsSummary != null && _dsSummary.Tables.Count > 3 && _dsSummary.Tables[3].Rows.Count > 0)
            {
                _dtCMISummary = _dsSummary.Tables[3];
                TotalCMIFileCount += _dtCMISummary.Rows.Count;
            }

            if (TotalFileCount > 0)
            {
                #region Variable Declaration
                string PaymentType = "";
                string[] CECarId = new string[TotalFileCount];
                string[] ProviderCompanyId = new string[TotalFileCount];
                string[] InsuranceType = new string[TotalFileCount];
                string[] GarageType = new string[TotalFileCount];
                decimal[] NetPremium = new decimal[TotalFileCount];

                string[] CProviderCompanyId = new string[TotalCMIFileCount];
                string[] CInsuranceType = new string[TotalCMIFileCount];
                string[] CGarageType = new string[TotalFileCount];
                decimal[] CNetPremium = new decimal[TotalCMIFileCount];
                string[] IsCTPL = new string[TotalCMIFileCount];

                string[] OICInsurer = new string[18];
                decimal[] OICVoluntary = new decimal[18];
                decimal[] OICCompulsory = new decimal[18];
                decimal[] OICTotal = new decimal[18];

                string[] IntInsurer = new string[18];
                decimal[] IntVoluntary = new decimal[18];
                decimal[] IntCompulsory = new decimal[18];
                decimal[] IntTotal = new decimal[18];

                string[] MktInsurer = new string[18];
                decimal[] MktVoluntary = new decimal[18];
                decimal[] MktCompulsory = new decimal[18];
                decimal[] MktTotal = new decimal[18];

                decimal OICVoluntaryTotal, OICCompulsoryTotal, OICFinalTotal;
                decimal IntVoluntaryTotal, IntCompulsoryTotal, IntFinalTotal;
                decimal MktVoluntaryTotal, MktCompulsoryTotal, MktFinalTotal;

                decimal C_OICAZC, C_IntAZC, C_MktAZC, V_OICAZC, V_IntAZC, V_MktAZC, Total_OICAZC, Total_IntAZC, Total_MktAZC;
                decimal C_OICAXA, C_IntAXA, C_MktAXA, V_OICAXA, V_IntAXA, V_MktAXA, Total_OICAXA, Total_IntAXA, Total_MktAXA;
                decimal C_OICBKI, C_IntBKI, C_MktBKI, V_OICBKI, V_IntBKI, V_MktBKI, Total_OICBKI, Total_IntBKI, Total_MktBKI;
                decimal C_OICCTS, C_IntCTS, C_MktCTS, V_OICCTS, V_IntCTS, V_MktCTS, Total_OICCTS, Total_IntCTS, Total_MktCTS;
                decimal C_OICKSK, C_IntKSK, C_MktKSK, V_OICKSK, V_IntKSK, V_MktKSK, Total_OICKSK, Total_IntKSK, Total_MktKSK;
                decimal C_OICLMG, C_IntLMG, C_MktLMG, V_OICLMG, V_IntLMG, V_MktLMG, Total_OICLMG, Total_IntLMG, Total_MktLMG;
                decimal C_OICMSI, C_IntMSI, C_MktMSI, V_OICMSI, V_IntMSI, V_MktMSI, Total_OICMSI, Total_IntMSI, Total_MktMSI;
                decimal C_OICMTI, C_IntMTI, C_MktMTI, V_OICMTI, V_IntMTI, V_MktMTI, Total_OICMTI, Total_IntMTI, Total_MktMTI;
                decimal C_OICTMS, C_IntTMS, C_MktTMS, V_OICTMS, V_IntTMS, V_MktTMS, Total_OICTMS, Total_IntTMS, Total_MktTMS;
                decimal C_OICKPI, C_IntKPI, C_MktKPI, V_OICKPI, V_IntKPI, V_MktKPI, Total_OICKPI, Total_IntKPI, Total_MktKPI;
                decimal C_OICMIR, C_IntMIR, C_MktMIR, V_OICMIR, V_IntMIR, V_MktMIR, Total_OICMIR, Total_IntMIR, Total_MktMIR;
                decimal C_OICSMK, C_IntSMK, C_MktSMK, V_OICSMK, V_IntSMK, V_MktSMK, Total_OICSMK, Total_IntSMK, Total_MktSMK;
                decimal C_OICVRY, C_IntVRY, C_MktVRY, V_OICVRY, V_IntVRY, V_MktVRY, Total_OICVRY, Total_IntVRY, Total_MktVRY;
                decimal C_OICTVV, C_IntTVV, C_MktTVV, V_OICTVV, V_IntTVV, V_MktTVV, Total_OICTVV, Total_IntTVV, Total_MktTVV;
                decimal C_OICSCS, C_IntSCS, C_MktSCS, V_OICSCS, V_IntSCS, V_MktSCS, Total_OICSCS, Total_IntSCS, Total_MktSCS;
                decimal C_OICDYP, C_IntDYP, C_MktDYP, V_OICDYP, V_IntDYP, V_MktDYP, Total_OICDYP, Total_IntDYP, Total_MktDYP;
                decimal C_OICSMG, C_IntSMG, C_MktSMG, V_OICSMG, V_IntSMG, V_MktSMG, Total_OICSMG, Total_IntSMG, Total_MktSMG;
                decimal C_OICTPB, C_IntTPB, C_MktTPB, V_OICTPB, V_IntTPB, V_MktTPB, Total_OICTPB, Total_IntTPB, Total_MktTPB;

                OICVoluntaryTotal = 0; OICCompulsoryTotal = 0; OICFinalTotal = 0;
                IntVoluntaryTotal = 0; IntCompulsoryTotal = 0; IntFinalTotal = 0;
                MktVoluntaryTotal = 0; MktCompulsoryTotal = 0; MktFinalTotal = 0;

                C_OICAZC = 0; C_IntAZC = 0; C_MktAZC = 0; V_OICAZC = 0; V_IntAZC = 0; V_MktAZC = 0; Total_OICAZC = 0; Total_IntAZC = 0; Total_MktAZC = 0;
                C_OICAXA = 0; C_IntAXA = 0; C_MktAXA = 0; V_OICAXA = 0; V_IntAXA = 0; V_MktAXA = 0; Total_OICAXA = 0; Total_IntAXA = 0; Total_MktAXA = 0;
                C_OICBKI = 0; C_IntBKI = 0; C_MktBKI = 0; V_OICBKI = 0; V_IntBKI = 0; V_MktBKI = 0; Total_OICBKI = 0; Total_IntBKI = 0; Total_MktBKI = 0;
                C_OICCTS = 0; C_IntCTS = 0; C_MktCTS = 0; V_OICCTS = 0; V_IntCTS = 0; V_MktCTS = 0; Total_OICCTS = 0; Total_IntCTS = 0; Total_MktCTS = 0;
                C_OICKSK = 0; C_IntKSK = 0; C_MktKSK = 0; V_OICKSK = 0; V_IntKSK = 0; V_MktKSK = 0; Total_OICKSK = 0; Total_IntKSK = 0; Total_MktKSK = 0;
                C_OICLMG = 0; C_IntLMG = 0; C_MktLMG = 0; V_OICLMG = 0; V_IntLMG = 0; V_MktLMG = 0; Total_OICLMG = 0; Total_IntLMG = 0; Total_MktLMG = 0;
                C_OICMSI = 0; C_IntMSI = 0; C_MktMSI = 0; V_OICMSI = 0; V_IntMSI = 0; V_MktMSI = 0; Total_OICMSI = 0; Total_IntMSI = 0; Total_MktMSI = 0;
                C_OICMTI = 0; C_IntMTI = 0; C_MktMTI = 0; V_OICMTI = 0; V_IntMTI = 0; V_MktMTI = 0; Total_OICMTI = 0; Total_IntMTI = 0; Total_MktMTI = 0;
                C_OICTMS = 0; C_IntTMS = 0; C_MktTMS = 0; V_OICTMS = 0; V_IntTMS = 0; V_MktTMS = 0; Total_OICTMS = 0; Total_IntTMS = 0; Total_MktTMS = 0;
                C_OICKPI = 0; C_IntKPI = 0; C_MktKPI = 0; V_OICKPI = 0; V_IntKPI = 0; V_MktKPI = 0; Total_OICKPI = 0; Total_IntKPI = 0; Total_MktKPI = 0;
                C_OICMIR = 0; C_IntMIR = 0; C_MktMIR = 0; V_OICMIR = 0; V_IntMIR = 0; V_MktMIR = 0; Total_OICMIR = 0; Total_IntMIR = 0; Total_MktMIR = 0;
                C_OICSMK = 0; C_IntSMK = 0; C_MktSMK = 0; V_OICSMK = 0; V_IntSMK = 0; V_MktSMK = 0; Total_OICSMK = 0; Total_IntSMK = 0; Total_MktSMK = 0;
                C_OICVRY = 0; C_IntVRY = 0; C_MktVRY = 0; V_OICVRY = 0; V_IntVRY = 0; V_MktVRY = 0; Total_OICVRY = 0; Total_IntVRY = 0; Total_MktVRY = 0;
                C_OICTVV = 0; C_IntTVV = 0; C_MktTVV = 0; V_OICTVV = 0; V_IntTVV = 0; V_MktTVV = 0; Total_OICTVV = 0; Total_IntTVV = 0; Total_MktTVV = 0;
                C_OICSCS = 0; C_IntSCS = 0; C_MktSCS = 0; V_OICSCS = 0; V_IntSCS = 0; V_MktSCS = 0; Total_OICSCS = 0; Total_IntSCS = 0; Total_MktSCS = 0;
                C_OICDYP = 0; C_IntDYP = 0; C_MktDYP = 0; V_OICDYP = 0; V_IntDYP = 0; V_MktDYP = 0; Total_OICDYP = 0; Total_IntDYP = 0; Total_MktDYP = 0;
                C_OICSMG = 0; C_IntSMG = 0; C_MktSMG = 0; V_OICSMG = 0; V_IntSMG = 0; V_MktSMG = 0; Total_OICSMG = 0; Total_IntSMG = 0; Total_MktSMG = 0;
                C_OICTPB = 0; C_IntTPB = 0; C_MktTPB = 0; V_OICTPB = 0; V_IntTPB = 0; V_MktTPB = 0; Total_OICTPB = 0; Total_IntTPB = 0; Total_MktTPB = 0;
                #endregion

                #region Default Value for OIC & Internal Reports
                //OIC
                OICInsurer[0] = GetProvider(16);
                OICInsurer[1] = GetProvider(11);
                OICInsurer[2] = GetProvider(32);
                OICInsurer[3] = GetProvider(31);
                OICInsurer[4] = GetProvider(35);
                OICInsurer[5] = GetProvider(41);
                OICInsurer[6] = GetProvider(29);
                OICInsurer[7] = GetProvider(12);
                OICInsurer[8] = GetProvider(33);
                OICInsurer[9] = GetProvider(46);
                OICInsurer[10] = GetProvider(39);
                OICInsurer[11] = GetProvider(43);
                OICInsurer[12] = GetProvider(45);
                OICInsurer[13] = GetProvider(58);
                OICInsurer[14] = GetProvider(50);
                OICInsurer[15] = GetProvider(65);
                OICInsurer[16] = GetProvider(51);
                OICInsurer[17] = GetProvider(66);

                OICVoluntary[0] = 0;//"0";
                OICVoluntary[1] = 0;//"0";
                OICVoluntary[2] = 0;//"0";
                OICVoluntary[3] = 0;//"0";
                OICVoluntary[4] = 0;//"0";
                OICVoluntary[5] = 0;//"0";
                OICVoluntary[6] = 0;//"0";
                OICVoluntary[7] = 0;//"0";
                OICVoluntary[8] = 0;//"0";
                OICVoluntary[9] = 0;//"0";
                OICVoluntary[10] = 0;//"0";
                OICVoluntary[11] = 0;//"0";
                OICVoluntary[12] = 0;//"0";
                OICVoluntary[13] = 0;// "0";
                OICVoluntary[14] = 0;//"0";
                OICVoluntary[15] = 0;//"0";
                OICVoluntary[16] = 0;//"0";
                OICVoluntary[17] = 0;//"0";

                OICCompulsory[0] = 0;//"0";
                OICCompulsory[1] = 0;//"0";
                OICCompulsory[2] = 0;//"0";
                OICCompulsory[3] = 0;//"0";
                OICCompulsory[4] = 0;//"0";
                OICCompulsory[5] = 0;//"0";
                OICCompulsory[6] = 0;//"0";
                OICCompulsory[7] = 0;//"0";
                OICCompulsory[8] = 0;//"0";
                OICCompulsory[9] = 0;//"0";
                OICCompulsory[10] = 0;//"0";
                OICCompulsory[11] = 0;//"0";
                OICCompulsory[12] = 0;//"0";
                OICCompulsory[13] = 0;//"0";
                OICCompulsory[14] = 0;//"0";
                OICCompulsory[15] = 0;//"0";
                OICCompulsory[16] = 0;//"0";
                OICCompulsory[17] = 0;//"0";

                OICTotal[0] = 0;//"0";
                OICTotal[1] = 0;//"0";
                OICTotal[2] = 0;//"0";
                OICTotal[3] = 0;//"0";
                OICTotal[4] = 0;//"0";
                OICTotal[5] = 0;//"0";
                OICTotal[6] = 0;//"0";
                OICTotal[7] = 0;//"0";
                OICTotal[8] = 0;//"0";
                OICTotal[9] = 0;//"0";
                OICTotal[10] = 0;//"0";
                OICTotal[11] = 0;//"0";
                OICTotal[12] = 0;//"0";
                OICTotal[13] = 0;//"0";
                OICTotal[14] = 0;//"0";
                OICTotal[15] = 0;//"0";
                OICTotal[16] = 0;//"0";
                OICTotal[17] = 0;//"0";

                //Internal
                IntInsurer[0] = GetProvider(16);
                IntInsurer[1] = GetProvider(11);
                IntInsurer[2] = GetProvider(32);
                IntInsurer[3] = GetProvider(31);
                IntInsurer[4] = GetProvider(35);
                IntInsurer[5] = GetProvider(41);
                IntInsurer[6] = GetProvider(29);
                IntInsurer[7] = GetProvider(12);
                IntInsurer[8] = GetProvider(33);
                IntInsurer[9] = GetProvider(46);
                IntInsurer[10] = GetProvider(39);
                IntInsurer[11] = GetProvider(43);
                IntInsurer[12] = GetProvider(45);
                IntInsurer[13] = GetProvider(58);
                IntInsurer[14] = GetProvider(50);
                IntInsurer[15] = GetProvider(65);
                IntInsurer[16] = GetProvider(51);
                IntInsurer[17] = GetProvider(66);

                IntVoluntary[0] = 0;//"0";
                IntVoluntary[1] = 0;//"0";
                IntVoluntary[2] = 0;//"0";
                IntVoluntary[3] = 0;//"0";
                IntVoluntary[4] = 0;//"0";
                IntVoluntary[5] = 0;//"0";
                IntVoluntary[6] = 0;//"0";
                IntVoluntary[7] = 0;//"0";
                IntVoluntary[8] = 0;//"0";
                IntVoluntary[9] = 0;//"0";
                IntVoluntary[10] = 0;//"0";
                IntVoluntary[11] = 0;//"0";
                IntVoluntary[12] = 0;//"0";
                IntVoluntary[13] = 0;//"0";
                IntVoluntary[13] = 0;//"0";
                IntVoluntary[14] = 0;//"0";
                IntVoluntary[15] = 0;//"0";
                IntVoluntary[16] = 0;//"0";
                IntVoluntary[17] = 0;//"0";

                IntCompulsory[0] = 0;//"0";
                IntCompulsory[1] = 0;//"0";
                IntCompulsory[2] = 0;//"0";
                IntCompulsory[3] = 0;//"0";
                IntCompulsory[4] = 0;//"0";
                IntCompulsory[5] = 0;//"0";
                IntCompulsory[6] = 0;//"0";
                IntCompulsory[7] = 0;//"0";
                IntCompulsory[8] = 0;//"0";
                IntCompulsory[9] = 0;//"0";
                IntCompulsory[10] = 0;//"0";
                IntCompulsory[11] = 0;//"0";
                IntCompulsory[12] = 0;//"0";
                IntCompulsory[13] = 0;//"0";
                IntCompulsory[14] = 0;//"0";
                IntCompulsory[15] = 0;//"0";
                IntCompulsory[16] = 0;//"0";
                IntCompulsory[17] = 0;//"0";

                IntTotal[0] = 0;//"0";
                IntTotal[1] = 0;//"0";
                IntTotal[2] = 0;//"0";
                IntTotal[3] = 0;//"0";
                IntTotal[4] = 0;//"0";
                IntTotal[5] = 0;//"0";
                IntTotal[6] = 0;//"0";
                IntTotal[7] = 0;//"0";
                IntTotal[8] = 0;//"0";
                IntTotal[9] = 0;//"0";
                IntTotal[10] = 0;//"0";
                IntTotal[11] = 0;//"0";
                IntTotal[12] = 0;//"0";
                IntTotal[13] = 0;//"0";
                IntTotal[14] = 0;//"0";
                IntTotal[15] = 0;//"0";
                IntTotal[16] = 0;//"0";
                IntTotal[17] = 0;//"0";

                //Marketing
                MktInsurer[0] = GetProvider(16);
                MktInsurer[1] = GetProvider(11);
                MktInsurer[2] = GetProvider(32);
                MktInsurer[3] = GetProvider(31);
                MktInsurer[4] = GetProvider(35);
                MktInsurer[5] = GetProvider(41);
                MktInsurer[6] = GetProvider(29);
                MktInsurer[7] = GetProvider(12);
                MktInsurer[8] = GetProvider(33);
                MktInsurer[9] = GetProvider(46);
                MktInsurer[10] = GetProvider(39);
                MktInsurer[11] = GetProvider(43);
                MktInsurer[12] = GetProvider(45);
                MktInsurer[13] = GetProvider(58);
                MktInsurer[14] = GetProvider(50);
                MktInsurer[15] = GetProvider(65);
                MktInsurer[16] = GetProvider(51);
                MktInsurer[17] = GetProvider(66);

                MktVoluntary[0] = 0;//"0";
                MktVoluntary[1] = 0;//"0";
                MktVoluntary[2] = 0;//"0";
                MktVoluntary[3] = 0;//"0";
                MktVoluntary[4] = 0;//"0";
                MktVoluntary[5] = 0;//"0";
                MktVoluntary[6] = 0;//"0";
                MktVoluntary[7] = 0;//"0";
                MktVoluntary[8] = 0;//"0";
                MktVoluntary[9] = 0;//"0";
                MktVoluntary[10] = 0;//"0";
                MktVoluntary[11] = 0;//"0";
                MktVoluntary[12] = 0;//"0";
                MktVoluntary[13] = 0;//"0";
                MktVoluntary[14] = 0;//"0";
                MktVoluntary[15] = 0;//"0";
                MktVoluntary[16] = 0;//"0";
                MktVoluntary[17] = 0;//"0";

                MktCompulsory[0] = 0;//"0";
                MktCompulsory[1] = 0;//"0";
                MktCompulsory[2] = 0;//"0";
                MktCompulsory[3] = 0;//"0";
                MktCompulsory[4] = 0;//"0";
                MktCompulsory[5] = 0;//"0";
                MktCompulsory[6] = 0;//"0";
                MktCompulsory[7] = 0;//"0";
                MktCompulsory[8] = 0;//"0";
                MktCompulsory[9] = 0;//"0";
                MktCompulsory[10] = 0;//"0";
                MktCompulsory[11] = 0;//"0";
                MktCompulsory[12] = 0;//"0";
                MktCompulsory[13] = 0;//"0";
                MktCompulsory[14] = 0;//"0";
                MktCompulsory[15] = 0;//"0";
                MktCompulsory[16] = 0;//"0";
                MktCompulsory[17] = 0;//"0";

                MktTotal[0] = 0;//"0";
                MktTotal[1] = 0;//"0";
                MktTotal[2] = 0;//"0";
                MktTotal[3] = 0;//"0";
                MktTotal[4] = 0;//"0";
                MktTotal[5] = 0;//"0";
                MktTotal[6] = 0;//"0";
                MktTotal[7] = 0;//"0";
                MktTotal[8] = 0;//"0";
                MktTotal[9] = 0;//"0";
                MktTotal[10] = 0;//"0";
                MktTotal[11] = 0;//"0";
                MktTotal[12] = 0;//"0";
                MktTotal[13] = 0;//"0";
                MktTotal[14] = 0;//"0";
                MktTotal[15] = 0;//"0";
                MktTotal[16] = 0;//"0";
                MktTotal[17] = 0;//"0";
                #endregion

                for (int i = 0; i < TotalFileCount; i++)
                {
                    #region Value Assign
                    decimal _vTempNetPremium = 0;
                    CECarId[i] = _dtSummary.Rows[i]["CECarId"].ToString();
                    ProviderCompanyId[i] = _dtSummary.Rows[i]["ProviderCompanyId"].ToString();
                    InsuranceType[i] = _dtSummary.Rows[i]["InsuranceTypeId"].ToString();
                    GarageType[i] = _dtSummary.Rows[i]["GarageType"].ToString();
                    if(!decimal.TryParse(_dtSummary.Rows[i]["NetPremium"].ToString(), out _vTempNetPremium))
                    {
                        _vTempNetPremium = 0;
                    }
                    NetPremium[i] = _vTempNetPremium;                                  
                    #endregion
                }

                for (int j = 0; j < TotalCMIFileCount; j++)
                {
                    #region Value Assign
                    decimal _cTempNetPremium = 0;
                    IsCTPL[j] = _dtCMISummary.Rows[j]["IsCTPL"].ToString();  
                    CProviderCompanyId[j] = _dtCMISummary.Rows[j]["ProviderCompanyId"].ToString();
                    CInsuranceType[j] = _dtCMISummary.Rows[j]["InsuranceTypeId"].ToString();
                    CGarageType[j] = _dtCMISummary.Rows[j]["GarageType"].ToString();
                    if (!decimal.TryParse(_dtCMISummary.Rows[j]["NetPremium"].ToString(), out _cTempNetPremium))
                    {
                        _cTempNetPremium = 0;
                    }
                    CNetPremium[j] = _cTempNetPremium;    
                    #endregion
                }

                #region Value for OIC & Internal Reports
                decimal _IntPer = 0;
                decimal _MktPer = 0;
                decimal _OICPer = 0;
                Int64 _InsType = 0;
                Int16 _Garage = 0;
                DataTable _dtPer = new DataTable();

                #region VMI
                for (int v = 0; v < TotalFileCount; v++)
                {
                    _IntPer = 0;
                    _MktPer = 0;
                    _OICPer = 0;
                    _InsType = 0;
                    _Garage = 0;

                    #region AXA
                    V_IntAXA = 0;
                    V_MktAXA = 0;
                    V_OICAXA = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "16")
                    {
                        if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() == "10" || InsuranceType[v].ToString().Trim() == "11"))
                        {
                            _InsType = 1011;
                        }
                        _dtPer = GetPercentage(16, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntAXA = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktAXA = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICAXA = Math.Round((NetPremium[v] * _OICPer), 2);
                        }                        
                        Total_IntAXA = Total_IntAXA + V_IntAXA;
                        Total_MktAXA = Total_MktAXA + V_IntAXA;
                        Total_OICAXA = Total_OICAXA + V_IntAXA;
                        //IntVoluntary[1] = IntVoluntary[1] + V_IntAXA;
                        //MktVoluntary[1] = MktVoluntary[1] + V_MktAXA;
                        //OICVoluntary[1] = OICVoluntary[1] + V_OICAXA;
                    }
                    #endregion

                    #region AZCP
                    V_IntAZC = 0;
                    V_MktAZC = 0;
                    V_OICAZC = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "11")
                    {
                        if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() == "10" || InsuranceType[v].ToString().Trim() == "11") && GarageType[v].ToString().Trim() == "1")
                        {
                            _InsType = 1011;
                            _Garage = 1;
                        }
                        else if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() == "10" || InsuranceType[v].ToString().Trim() == "11") && GarageType[v].ToString().Trim() == "2")
                        {
                            _InsType = 1011;
                            _Garage = 2;
                        }
                        else if (InsuranceType[v].ToString() != string.Empty && InsuranceType[v].ToString().Trim() == "21" || InsuranceType[v].ToString().Trim() == "31")
                        {
                            _InsType = 2131;
                            _Garage = 0;
                        }
                        else if (InsuranceType[v].ToString() != string.Empty && InsuranceType[v].ToString().Trim() == "30")
                        {
                            _InsType = 30;
                            _Garage = 0;
                        }
                        _dtPer = GetPercentage(11, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntAZC = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktAZC = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICAZC = Math.Round((NetPremium[v] * _OICPer), 2);
                        }
                        Total_IntAZC = Total_IntAZC + V_IntAZC;
                        Total_MktAZC = Total_MktAZC + V_MktAZC;
                        Total_OICAZC = Total_OICAZC + V_OICAZC;
                        //IntVoluntary[2] = IntVoluntary[2] + V_IntAZC;
                        //MktVoluntary[2] = MktVoluntary[2] + V_MktAZC;
                        //OICVoluntary[2] = OICVoluntary[2] + V_OICAZC;
                    }
                    #endregion

                    #region BKI
                    V_IntBKI = 0;
                    V_MktBKI = 0;
                    V_OICBKI = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "32")
                    {
                        _dtPer = GetPercentage(32, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntBKI = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktBKI = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICBKI = Math.Round((NetPremium[v] * _OICPer), 2);
                        }

                        Total_IntBKI = Total_IntBKI + V_IntBKI;
                        Total_MktBKI = Total_MktBKI + V_MktBKI;
                        Total_OICBKI = Total_OICBKI + V_OICBKI;
                        //IntVoluntary[3] = IntVoluntary[3] + V_IntBKI;
                        //MktVoluntary[3] = MktVoluntary[3] + V_MktBKI;
                        //OICVoluntary[3] = OICVoluntary[3] + V_OICBKI;
                    }
                    #endregion

                    #region Chartis
                    V_IntCTS = 0;
                    V_MktCTS = 0;
                    V_OICCTS = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "31")
                    {
                        _dtPer = GetPercentage(31, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntCTS = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktCTS = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICCTS = Math.Round((NetPremium[v] * _OICPer), 2);
                        }

                        Total_IntCTS = Total_IntCTS + V_IntCTS;
                        Total_MktCTS = Total_MktCTS + V_MktCTS;
                        Total_OICCTS = Total_OICCTS + V_OICCTS;
                    }
                    #endregion

                    #region Kurnia
                    V_IntKSK = 0;
                    V_MktKSK = 0;
                    V_OICKSK = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "41")
                    {
                        if (InsuranceType[v].ToString() != string.Empty && InsuranceType[v].ToString().Trim() != "11")
                        {
                            _InsType = 0;
                        }
                        else if (InsuranceType[v].ToString() != string.Empty && InsuranceType[v].ToString().Trim() == "11")
                        {
                            _InsType = 11;
                        }
                        _dtPer = GetPercentage(41, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntKSK = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktKSK = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICKSK = Math.Round((NetPremium[v] * _OICPer), 2);
                        }
                        Total_IntKSK = Total_IntKSK + V_IntKSK;
                        Total_MktKSK = Total_MktKSK + V_MktKSK;
                        Total_OICKSK = Total_OICKSK + V_OICKSK;
                    }
                    #endregion

                    #region LMG
                    V_IntLMG = 0;
                    V_MktLMG = 0;
                    V_OICLMG = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "29")
                    {
                        if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() == "10" || InsuranceType[v].ToString().Trim() == "11"))
                        {
                            _InsType = 1011;
                        }
                        else if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() != "10" && InsuranceType[v].ToString().Trim() != "11"))
                        {
                            _InsType = 0;
                        }
                        _dtPer = GetPercentage(29, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntLMG = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktLMG = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICLMG = Math.Round((NetPremium[v] * _OICPer), 2);
                        }
                        Total_IntLMG = Total_IntLMG + V_IntLMG;
                        Total_MktLMG = Total_MktLMG + V_MktLMG;
                        Total_OICLMG = Total_OICLMG + V_OICLMG;
                    }
                    #endregion

                    #region MSIG
                    V_IntMSI = 0;
                    V_MktMSI = 0;
                    V_OICMSI = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "12")
                    {
                        _dtPer = GetPercentage(12, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntMSI = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktMSI = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICMSI = Math.Round((NetPremium[v] * _OICPer), 2);
                        }

                        Total_IntMSI = Total_IntMSI + V_IntMSI;
                        Total_MktMSI = Total_MktMSI + V_MktMSI;
                        Total_OICMSI = Total_OICMSI + V_OICMSI;
                    }
                    #endregion

                    #region MuangThai
                    V_IntMTI = 0;
                    V_MktMTI = 0;
                    V_OICMTI = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "33")
                    {
                        if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() == "10" || InsuranceType[v].ToString().Trim() == "11"))
                        {
                            _InsType = 1011;
                        }
                        else if (InsuranceType[v].ToString() != string.Empty && InsuranceType[v].ToString().Trim() == "21" || InsuranceType[v].ToString().Trim() == "31")
                        {
                            _InsType = 2131;
                        }
                        else if (InsuranceType[v].ToString() != string.Empty && InsuranceType[v].ToString().Trim() == "30")
                        {
                            _InsType = 30;
                        }
                        _dtPer = GetPercentage(33, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntMTI = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktMTI = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICMTI = Math.Round((NetPremium[v] * _OICPer), 2);
                        }
                        Total_IntMTI = Total_IntMTI + V_IntMTI;
                        Total_MktMTI = Total_MktMTI + V_MktMTI;
                        Total_OICMTI = Total_OICMTI + V_OICMTI;
                    }
                    #endregion

                    #region Tokio Marine
                    V_IntTMS = 0;
                    V_MktTMS = 0;
                    V_OICTMS = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "46")
                    {
                        if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() == "10" || InsuranceType[v].ToString().Trim() == "11"))
                        {
                            _InsType = 1011;
                        }
                        else if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() != "10" && InsuranceType[v].ToString().Trim() != "11"))
                        {
                            _InsType = 0;
                        }
                        _dtPer = GetPercentage(46, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntTMS = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktTMS = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICTMS = Math.Round((NetPremium[v] * _OICPer), 2);
                        }
                        Total_IntTMS = Total_IntTMS + V_IntTMS;
                        Total_MktTMS = Total_MktTMS + V_MktTMS;
                        Total_OICTMS = Total_OICTMS + V_OICTMS;
                    }
                    #endregion

                    #region KrungThai
                    V_IntKPI = 0;
                    V_MktKPI = 0;
                    V_OICKPI = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "35")
                    {
                        if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() == "10" || InsuranceType[v].ToString().Trim() == "11"))
                        {
                            _InsType = 1011;
                        }
                        else if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() != "10" && InsuranceType[v].ToString().Trim() != "11"))
                        {
                            _InsType = 0;
                        }
                        _dtPer = GetPercentage(35, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntKPI = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktKPI = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICKPI = Math.Round((NetPremium[v] * _OICPer), 2);
                        }
                        Total_IntKPI = Total_IntKPI + V_IntKPI;
                        Total_MktKPI = Total_MktKPI + V_MktKPI;
                        Total_OICKPI = Total_OICKPI + V_OICKPI;
                    }
                    #endregion

                    #region Mittare
                    V_IntMIR = 0;
                    V_MktMIR = 0;
                    V_OICMIR = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "39")
                    {
                        _dtPer = GetPercentage(39, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntMIR = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktMIR = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICMIR = Math.Round((NetPremium[v] * _OICPer), 2);
                        }

                        Total_IntMIR = Total_IntMIR + V_IntMIR;
                        Total_MktMIR = Total_MktMIR + V_MktMIR;
                        Total_OICMIR = Total_OICMIR + V_OICMIR;
                    }
                    #endregion

                    #region Syn Mun Kong
                    V_IntSMK = 0;
                    V_MktSMK = 0;
                    V_OICSMK = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "43")
                    {
                        _dtPer = GetPercentage(43, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntSMK = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktSMK = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICSMK = Math.Round((NetPremium[v] * _OICPer), 2);
                        }

                        Total_IntSMK = Total_IntSMK + V_IntSMK;
                        Total_MktSMK = Total_MktSMK + V_MktSMK;
                        Total_OICSMK = Total_OICSMK + V_OICSMK;
                    }
                    #endregion

                    #region Viriyah
                    V_IntVRY = 0;
                    V_MktVRY = 0;
                    V_OICVRY = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "45")
                    {
                        _dtPer = GetPercentage(45, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntVRY = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktVRY = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICVRY = Math.Round((NetPremium[v] * _OICPer), 2);
                        }

                        Total_IntVRY = Total_IntVRY + V_IntVRY;
                        Total_MktVRY = Total_MktVRY + V_MktVRY;
                        Total_OICVRY = Total_OICVRY + V_OICVRY;
                    }
                    #endregion

                    #region Thaivivat
                    V_IntTVV = 0;
                    V_MktTVV = 0;
                    V_OICTVV = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "58")
                    {
                        _dtPer = GetPercentage(58, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntTVV = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktTVV = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICTVV = Math.Round((NetPremium[v] * _OICPer), 2);
                        }

                        Total_IntTVV = Total_IntTVV + V_IntTVV;
                        Total_MktTVV = Total_MktTVV + V_MktTVV;
                        Total_OICTVV = Total_OICTVV + V_OICTVV;
                    }
                    #endregion

                    #region SCSMG
                    V_IntSCS = 0;
                    V_MktSCS = 0;
                    V_OICSCS = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "50")
                    {
                        if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() == "10" || InsuranceType[v].ToString().Trim() == "11"))
                        {
                            _InsType = 1011;
                        }
                        else if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() != "10" && InsuranceType[v].ToString().Trim() != "11"))
                        {
                            _InsType = 0;
                        }                        
                        _dtPer = GetPercentage(50, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntSCS = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktSCS = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICSCS = Math.Round((NetPremium[v] * _OICPer), 2);
                        }
                        Total_IntSCS = Total_IntSCS + V_IntSCS;
                        Total_MktSCS = Total_MktSCS + V_MktSCS;
                        Total_OICSCS = Total_OICSCS + V_OICSCS;
                    }
                    #endregion

                    #region Dhipaya
                    V_IntDYP = 0;
                    V_MktDYP = 0;
                    V_OICDYP = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "65")
                    {
                        _dtPer = GetPercentage(65, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntDYP = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktDYP = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICDYP = Math.Round((NetPremium[v] * _OICPer), 2);
                        }

                        Total_IntDYP = Total_IntDYP + V_IntDYP;
                        Total_IntDYP = Total_IntDYP + V_MktDYP;
                        Total_OICDYP = Total_OICDYP + V_OICDYP;
                    }
                    #endregion

                    #region SMG
                    V_IntSMG = 0;
                    V_MktSMG = 0;
                    V_OICSMG = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "51")
                    {
                        if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() == "10" || InsuranceType[v].ToString().Trim() == "11"))
                        {
                            _InsType = 1011;
                        }
                        else if (InsuranceType[v].ToString() != string.Empty && (InsuranceType[v].ToString().Trim() != "10" && InsuranceType[v].ToString().Trim() != "11"))
                        {
                            _InsType = 0;
                        }
                        _dtPer = GetPercentage(51, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntSMG = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktSMG = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICSMG = Math.Round((NetPremium[v] * _OICPer), 2);
                        }
                        Total_IntSMG = Total_IntSMG + V_IntSMG;
                        Total_MktSMG = Total_MktSMG + V_MktSMG;
                        Total_OICSMG = Total_OICSMG + V_OICSMG;
                    }
                    #endregion

                    #region TPB
                    V_IntTPB = 0;
                    V_MktTPB = 0;
                    V_OICTPB = 0;
                    if (ProviderCompanyId[v].ToString() != string.Empty && ProviderCompanyId[v].ToString().Trim() == "66")
                    {
                        _dtPer = GetPercentage(66, "VMI", _InsType, _Garage, txtReportDate.Text.Trim());
                        if (_dtPer != null && _dtPer.Rows.Count > 0)
                        {
                            if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                            {
                                _IntPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                            {
                                _MktPer = 0;
                            }
                            if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                            {
                                _OICPer = 0;
                            }
                            V_IntTPB = Math.Round((NetPremium[v] * _IntPer), 2);
                            V_MktTPB = Math.Round((NetPremium[v] * _MktPer), 2);
                            V_OICTPB = Math.Round((NetPremium[v] * _OICPer), 2);
                        }

                        Total_IntTPB = Total_IntTPB + V_IntTPB;
                        Total_IntTPB = Total_IntTPB + V_MktTPB;
                        Total_OICTPB = Total_OICTPB + V_OICTPB;
                    }
                    #endregion

                }
                IntVoluntary[0] = IntVoluntary[0] + Total_IntAXA;
                MktVoluntary[0] = MktVoluntary[0] + Total_MktAXA;
                OICVoluntary[0] = OICVoluntary[0] + Total_OICAXA;

                IntVoluntary[1] = IntVoluntary[1] + Total_IntAZC;
                MktVoluntary[1] = MktVoluntary[1] + Total_MktAZC;
                OICVoluntary[1] = OICVoluntary[1] + Total_OICAZC;

                IntVoluntary[2] = IntVoluntary[2] + Total_IntBKI;
                MktVoluntary[2] = MktVoluntary[2] + Total_MktBKI;
                OICVoluntary[2] = OICVoluntary[2] + Total_OICBKI;

                IntVoluntary[3] = IntVoluntary[3] + Total_IntCTS;
                MktVoluntary[3] = MktVoluntary[3] + Total_MktCTS;
                OICVoluntary[3] = OICVoluntary[3] + Total_OICCTS;

                IntVoluntary[4] = IntVoluntary[4] + Total_IntKSK;
                MktVoluntary[4] = MktVoluntary[4] + Total_MktKSK;
                OICVoluntary[4] = OICVoluntary[4] + Total_OICKSK;

                IntVoluntary[5] = IntVoluntary[5] + Total_IntLMG;
                MktVoluntary[5] = MktVoluntary[5] + Total_MktLMG;
                OICVoluntary[5] = OICVoluntary[5] + Total_OICLMG;

                IntVoluntary[6] = IntVoluntary[6] + Total_IntMSI;
                MktVoluntary[6] = MktVoluntary[6] + Total_MktMSI;
                OICVoluntary[6] = OICVoluntary[6] + Total_OICMSI;

                IntVoluntary[7] = IntVoluntary[7] + Total_IntMTI;
                MktVoluntary[7] = MktVoluntary[7] + Total_MktMTI;
                OICVoluntary[7] = OICVoluntary[7] + Total_OICMTI;

                IntVoluntary[8] = IntVoluntary[8] + Total_IntTMS;
                MktVoluntary[8] = MktVoluntary[8] + Total_MktTMS;
                OICVoluntary[8] = OICVoluntary[8] + Total_OICTMS;

                IntVoluntary[9] = IntVoluntary[9] + Total_IntKPI;
                MktVoluntary[9] = MktVoluntary[9] + Total_MktKPI;
                OICVoluntary[9] = OICVoluntary[9] + Total_OICKPI;

                IntVoluntary[10] = IntVoluntary[10] + Total_IntMIR;
                MktVoluntary[10] = MktVoluntary[10] + Total_MktMIR;
                OICVoluntary[10] = OICVoluntary[10] + Total_OICMIR;

                IntVoluntary[11] = IntVoluntary[11] + Total_IntSMK;
                MktVoluntary[11] = MktVoluntary[11] + Total_MktSMK;
                OICVoluntary[11] = OICVoluntary[11] + Total_OICSMK;

                IntVoluntary[12] = IntVoluntary[12] + Total_IntVRY;
                MktVoluntary[12] = MktVoluntary[12] + Total_MktVRY;
                OICVoluntary[12] = OICVoluntary[12] + Total_OICVRY;

                IntVoluntary[13] = IntVoluntary[13] + Total_IntTVV;
                MktVoluntary[13] = MktVoluntary[13] + Total_MktTVV;
                OICVoluntary[13] = OICVoluntary[13] + Total_OICTVV;

                IntVoluntary[14] = IntVoluntary[14] + Total_IntSCS;
                MktVoluntary[14] = MktVoluntary[14] + Total_MktSCS;
                OICVoluntary[14] = OICVoluntary[14] + Total_OICSCS;

                IntVoluntary[15] = IntVoluntary[15] + Total_IntDYP;
                MktVoluntary[15] = MktVoluntary[15] + Total_MktDYP;
                OICVoluntary[15] = OICVoluntary[15] + Total_OICDYP;
                #endregion

                #region CMI
                for (int c = 0; c < TotalCMIFileCount; c++)
                {
                    _IntPer = 0;
                    _MktPer = 0;
                    _OICPer = 0;
                    _InsType = 0;
                    _Garage = 0;

                    #region AXA
                    C_IntAXA = 0;
                    C_MktAXA = 0;
                    C_OICAXA = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "16")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(16, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntAXA = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktAXA = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICAXA = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }                        
                        Total_IntAXA = Total_IntAXA + C_IntAXA;
                        Total_MktAXA = Total_MktAXA + C_IntAXA;
                        Total_OICAXA = Total_OICAXA + C_IntAXA;
                    }
                    #endregion

                    #region AZCP
                    C_IntAZC = 0;
                    C_MktAZC = 0;
                    C_OICAZC = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "11")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(11, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntAZC = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktAZC = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICAZC = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntAZC = Total_IntAZC + C_IntAZC;
                        Total_MktAZC = Total_MktAZC + C_MktAZC;
                        Total_OICAZC = Total_OICAZC + C_OICAZC;
                    }
                    #endregion

                    #region BKI
                    C_IntBKI = 0;
                    C_MktBKI = 0;
                    C_OICBKI = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "32")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(32, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntBKI = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktBKI = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICBKI = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntBKI = Total_IntBKI + C_IntBKI;
                        Total_MktBKI = Total_MktBKI + C_MktBKI;
                        Total_OICBKI = Total_OICBKI + C_OICBKI;
                    }
                    #endregion

                    #region Chartis
                    C_IntCTS = 0;
                    C_MktCTS = 0;
                    C_OICCTS = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "31")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(31, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntCTS = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktCTS = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICCTS = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntCTS = Total_IntCTS + C_IntCTS;
                        Total_MktCTS = Total_MktCTS + C_MktCTS;
                        Total_OICCTS = Total_OICCTS + C_OICCTS;
                    }
                    #endregion

                    #region Kurnia
                    C_IntKSK = 0;
                    C_MktKSK = 0;
                    C_OICKSK = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "41")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(41, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntKSK = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktKSK = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICKSK = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntKSK = Total_IntKSK + C_IntKSK;
                        Total_MktKSK = Total_MktKSK + C_MktKSK;
                        Total_OICKSK = Total_OICKSK + C_OICKSK;
                    }
                    #endregion

                    #region LMG
                    C_IntLMG = 0;
                    C_MktLMG = 0;
                    C_OICLMG = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "29")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(29, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntLMG = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktLMG = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICLMG = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntLMG = Total_IntLMG + C_IntLMG;
                        Total_MktLMG = Total_MktLMG + C_MktLMG;
                        Total_OICLMG = Total_OICLMG + C_OICLMG;
                    }
                    #endregion

                    #region MSIG
                    C_IntMSI = 0;
                    C_MktMSI = 0;
                    C_OICMSI = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "12")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(12, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntMSI = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktMSI = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICMSI = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntMSI = Total_IntMSI + C_IntMSI;
                        Total_MktMSI = Total_MktMSI + C_MktMSI;
                        Total_OICMSI = Total_OICMSI + C_OICMSI;
                    }
                    #endregion

                    #region MuangThai
                    C_IntMTI = 0;
                    C_MktMTI = 0;
                    C_OICMTI = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "33")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(33, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntMTI = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktMTI = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICMTI = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntMTI = Total_IntMTI + C_IntMTI;
                        Total_MktMTI = Total_MktMTI + C_MktMTI;
                        Total_OICMTI = Total_OICMTI + C_OICMTI;
                    }
                    #endregion

                    #region Tokio Marine
                    C_IntTMS = 0;
                    C_MktTMS = 0;
                    C_OICTMS = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "46")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(46, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntTMS = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktTMS = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICTMS = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntTMS = Total_IntTMS + C_IntTMS;
                        Total_MktTMS = Total_MktTMS + C_MktTMS;
                        Total_OICTMS = Total_OICTMS + C_OICTMS;
                    }
                    #endregion

                    #region KrungThai
                    C_IntKPI = 0;
                    C_MktKPI = 0;
                    C_OICKPI = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "35")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(35, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntKPI = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktKPI = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICKPI = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntKPI = Total_IntKPI + C_IntKPI;
                        Total_MktKPI = Total_MktKPI + C_MktKPI;
                        Total_OICKPI = Total_OICKPI + C_OICKPI;
                    }
                    #endregion

                    #region Mittare
                    C_IntMIR = 0;
                    C_MktMIR = 0;
                    C_OICMIR = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "39")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(39, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntMIR = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktMIR = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICMIR = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntMIR = Total_IntMIR + C_IntMIR;
                        Total_MktMIR = Total_MktMIR + C_MktMIR;
                        Total_OICMIR = Total_OICMIR + C_OICMIR;
                    }
                    #endregion

                    #region Syn Mun Kong
                    C_IntSMK = 0;
                    C_MktSMK = 0;
                    C_OICSMK = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "43")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(43, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntSMK = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktSMK = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICSMK = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntSMK = Total_IntSMK + C_IntSMK;
                        Total_MktSMK = Total_MktSMK + C_MktSMK;
                        Total_OICSMK = Total_OICSMK + C_OICSMK;
                    }
                    #endregion

                    #region Viriyah
                    C_IntVRY = 0;
                    C_MktVRY = 0;
                    C_OICVRY = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "45")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(45, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntVRY = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktVRY = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICVRY = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntVRY = Total_IntVRY + C_IntVRY;
                        Total_MktVRY = Total_MktVRY + C_MktVRY;
                        Total_OICVRY = Total_OICVRY + C_OICVRY;
                    }
                    #endregion

                    #region Thaivivat
                    C_IntTVV = 0;
                    C_MktTVV = 0;
                    C_OICTVV = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "58")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(58, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntTVV = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktTVV = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICTVV = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntTVV = Total_IntTVV + C_IntTVV;
                        Total_MktTVV = Total_MktTVV + C_MktTVV;
                        Total_OICTVV = Total_OICTVV + C_OICTVV;
                    }
                    #endregion

                    #region SCSMG
                    C_IntSCS = 0;
                    C_MktSCS = 0;
                    C_OICSCS = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "50")
                    {
                        if (CInsuranceType[c].ToString() != string.Empty && (CInsuranceType[c].ToString().Trim() == "10" || CInsuranceType[c].ToString().Trim() == "11"))
                        {
                            _InsType = 1011;
                        }
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(50, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntSCS = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktSCS = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICSCS = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntSCS = Total_IntSCS + C_IntSCS;
                        Total_MktSCS = Total_MktSCS + C_MktSCS;
                        Total_OICSCS = Total_OICSCS + C_OICSCS;
                    }
                    #endregion

                    #region Dhipaya
                    C_IntDYP = 0;
                    C_MktDYP = 0;
                    C_OICDYP = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "65")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(65, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntDYP = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktDYP = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICDYP = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }                        
                        Total_IntDYP = Total_IntDYP + C_IntDYP;
                        Total_IntDYP = Total_IntDYP + C_MktDYP;
                        Total_OICDYP = Total_OICDYP + C_OICDYP;
                    }
                    #endregion

                    #region SMG
                    C_IntSMG = 0;
                    C_MktSMG = 0;
                    C_OICSMG = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "51")
                    {
                        if (CInsuranceType[c].ToString() != string.Empty && (CInsuranceType[c].ToString().Trim() == "10" || CInsuranceType[c].ToString().Trim() == "11"))
                        {
                            _InsType = 1011;
                        }
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(51, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntSMG = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktSMG = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICSMG = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntSMG = Total_IntSMG + C_IntSMG;
                        Total_MktSMG = Total_MktSMG + C_MktSMG;
                        Total_OICSMG = Total_OICSMG + C_OICSMG;
                    }
                    #endregion

                    #region TPB
                    C_IntTPB = 0;
                    C_MktTPB = 0;
                    C_OICTPB = 0;
                    if (CProviderCompanyId[c].ToString() != string.Empty && CProviderCompanyId[c].ToString().Trim() == "66")
                    {
                        if (IsCTPL[c].ToString() != string.Empty && IsCTPL[c].ToString().ToUpper() == "YES")
                        {
                            _dtPer = GetPercentage(66, "CMI", _InsType, _Garage, txtReportDate.Text.Trim());
                            if (_dtPer != null && _dtPer.Rows.Count > 0)
                            {
                                if (!decimal.TryParse(_dtPer.Rows[0]["IternalCommission"].ToString(), out _IntPer))
                                {
                                    _IntPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["MarketingCommission"].ToString(), out _MktPer))
                                {
                                    _MktPer = 0;
                                }
                                if (!decimal.TryParse(_dtPer.Rows[0]["OICCommission"].ToString(), out _OICPer))
                                {
                                    _OICPer = 0;
                                }
                                C_IntTPB = Math.Round((CNetPremium[c] * _IntPer), 2);
                                C_MktTPB = Math.Round((CNetPremium[c] * _MktPer), 2);
                                C_OICTPB = Math.Round((CNetPremium[c] * _OICPer), 2);
                            }
                        }
                        Total_IntTPB = Total_IntTPB + C_IntTPB;
                        Total_IntTPB = Total_IntTPB + C_MktTPB;
                        Total_OICTPB = Total_OICTPB + C_OICTPB;
                    }
                    #endregion

                }
                IntCompulsory[0] = IntCompulsory[0] + Total_IntAXA;
                MktCompulsory[0] = MktCompulsory[0] + Total_MktAXA;
                OICCompulsory[0] = OICCompulsory[0] + Total_OICAXA;

                IntCompulsory[1] = IntCompulsory[1] + Total_IntAZC;
                MktCompulsory[1] = MktCompulsory[1] + Total_MktAZC;
                OICCompulsory[1] = OICCompulsory[1] + Total_OICAZC;

                IntCompulsory[2] = IntCompulsory[2] + Total_IntBKI;
                MktCompulsory[2] = MktCompulsory[2] + Total_MktBKI;
                OICCompulsory[2] = OICCompulsory[2] + Total_OICBKI;

                IntCompulsory[3] = IntCompulsory[3] + Total_IntCTS;
                MktCompulsory[3] = MktCompulsory[3] + Total_MktCTS;
                OICCompulsory[3] = OICCompulsory[3] + Total_OICCTS;

                IntCompulsory[4] = IntCompulsory[4] + Total_IntKSK;
                MktCompulsory[4] = MktCompulsory[4] + Total_MktKSK;
                OICCompulsory[4] = OICCompulsory[4] + Total_OICKSK;

                IntCompulsory[5] = IntCompulsory[5] + Total_IntLMG;
                MktCompulsory[5] = MktCompulsory[5] + Total_MktLMG;
                OICCompulsory[5] = OICCompulsory[5] + Total_OICLMG;

                IntCompulsory[6] = IntCompulsory[6] + Total_IntMSI;
                MktCompulsory[6] = MktCompulsory[6] + Total_MktMSI;
                OICCompulsory[6] = OICCompulsory[6] + Total_OICMSI;

                IntCompulsory[7] = IntCompulsory[7] + Total_IntMTI;
                MktCompulsory[7] = MktCompulsory[7] + Total_MktMTI;
                OICCompulsory[7] = OICCompulsory[7] + Total_OICMTI;

                IntCompulsory[8] = IntCompulsory[8] + Total_IntTMS;
                MktCompulsory[8] = MktCompulsory[8] + Total_MktTMS;
                OICCompulsory[8] = OICCompulsory[8] + Total_OICTMS;

                IntCompulsory[9] = IntCompulsory[9] + Total_IntKPI;
                MktCompulsory[9] = MktCompulsory[9] + Total_MktKPI;
                OICCompulsory[9] = OICCompulsory[9] + Total_OICKPI;

                IntCompulsory[10] = IntCompulsory[10] + Total_IntMIR;
                MktCompulsory[10] = MktCompulsory[10] + Total_MktMIR;
                OICCompulsory[10] = OICCompulsory[10] + Total_OICMIR;

                IntCompulsory[11] = IntCompulsory[11] + Total_IntSMK;
                MktCompulsory[11] = MktCompulsory[11] + Total_MktSMK;
                OICCompulsory[11] = OICCompulsory[11] + Total_OICSMK;

                IntCompulsory[12] = IntCompulsory[12] + Total_IntVRY;
                MktCompulsory[12] = MktCompulsory[12] + Total_MktVRY;
                OICCompulsory[12] = OICCompulsory[12] + Total_OICVRY;

                IntCompulsory[13] = IntCompulsory[13] + Total_IntTVV;
                MktCompulsory[13] = MktCompulsory[13] + Total_MktTVV;
                OICCompulsory[13] = OICCompulsory[13] + Total_OICTVV;

                IntCompulsory[14] = IntCompulsory[14] + Total_IntSCS;
                MktCompulsory[14] = MktCompulsory[14] + Total_MktSCS;
                OICCompulsory[14] = OICCompulsory[14] + Total_OICSCS;

                IntCompulsory[15] = IntCompulsory[15] + Total_IntDYP;
                MktCompulsory[15] = MktCompulsory[15] + Total_MktDYP;
                OICCompulsory[15] = OICCompulsory[15] + Total_OICDYP;
                #endregion
                #endregion

                #region Assign Value for OIC & Internal Reports
                for (int a = 0; a < 16; a++)
                {
                    IntTotal[a] = IntVoluntary[a] + IntCompulsory[a];
                    MktTotal[a] = MktVoluntary[a] + MktCompulsory[a];
                    OICTotal[a] = OICVoluntary[a] + OICCompulsory[a];

                    IntVoluntaryTotal = IntVoluntaryTotal + IntVoluntary[a];
                    MktVoluntaryTotal = MktVoluntaryTotal + MktVoluntary[a];
                    OICVoluntaryTotal = OICVoluntaryTotal + OICVoluntary[a];

                    IntCompulsoryTotal = IntCompulsoryTotal + IntCompulsory[a];
                    MktCompulsoryTotal = MktCompulsoryTotal + MktCompulsory[a];
                    OICCompulsoryTotal = OICCompulsoryTotal + OICCompulsory[a];

                    IntFinalTotal = IntFinalTotal + IntTotal[a];
                    MktFinalTotal = MktFinalTotal + MktTotal[a];
                    OICFinalTotal = OICFinalTotal + OICTotal[a];
                }
                string s = "";
                //OICVoluntaryTotal   = (V_OICAZC + V_OICAXA + V_OICBKI + V_OICCTS + V_OICKSK + V_OICMTI + V_OICLMG + V_OICMSI 
                //                    +  V_OICTMS + V_OICKPI + V_OICMIR + V_OICSMK + V_OICVRY + V_OICTVV + V_OICSCS + V_OICDYP);

                //OICCompulsoryTotal  = (C_OICAZC + C_OICAXA + C_OICBKI + C_OICCTS + C_OICKSK + C_OICMTI + C_OICLMG + V_OICMSI
                //                    +  C_OICTMS + C_OICKPI + C_OICMIR + C_OICSMK + C_OICVRY + C_OICTVV + C_OICSCS + V_OICDYP);

                //OICFinalTotal       = (Total_OICAZC + Total_OICAXA + Total_OICBKI + Total_OICCTS + Total_OICKSK + Total_OICMTI + Total_OICLMG + Total_OICMSI
                //                    +  Total_OICTMS + Total_OICKPI + Total_OICMIR + Total_OICSMK + Total_OICVRY + Total_OICTVV + Total_OICSCS + Total_OICDYP);

                //IntVoluntaryTotal   = (V_IntAZC + V_IntAXA + V_IntBKI + V_IntCTS + V_IntKSK + V_IntMTI + V_IntLMG + V_IntMSI
                //                    + V_IntTMS + V_IntKPI + V_IntMIR + V_IntSMK + V_IntVRY + V_IntTVV + V_IntSCS + V_IntDYP);

                //IntCompulsoryTotal  = (C_IntAZC + C_IntAXA + C_IntBKI + C_IntCTS + C_IntKSK + C_IntMTI + C_IntLMG + V_IntMSI
                //                    + C_IntTMS + C_IntKPI + C_IntMIR + C_IntSMK + C_IntVRY + C_IntTVV + C_IntSCS + V_IntDYP);

                //IntFinalTotal       = (Total_IntAZC + Total_IntAXA + Total_IntBKI + Total_IntCTS + Total_IntKSK + Total_IntMTI + Total_IntLMG + Total_IntMSI
                //                    + Total_IntTMS + Total_IntKPI + Total_IntMIR + Total_IntSMK + Total_IntVRY + Total_IntTVV + Total_IntSCS + Total_IntDYP);

                //MktVoluntaryTotal = (V_MktAZC + V_MktAXA + V_MktBKI + V_MktCTS + V_MktKSK + V_MktMTI + V_MktLMG + V_MktMSI
                //                    + V_MktTMS + V_MktKPI + V_MktMIR + V_MktSMK + V_MktVRY + V_MktTVV + V_MktSCS + V_MktDYP);

                //MktCompulsoryTotal = (C_MktAZC + C_MktAXA + C_MktBKI + C_MktCTS + C_MktKSK + C_MktMTI + C_MktLMG + V_MktMSI
                //                    + C_MktTMS + C_MktKPI + C_MktMIR + C_MktSMK + C_MktVRY + C_MktTVV + C_MktSCS + V_MktDYP);

                //MktFinalTotal = (Total_MktAZC + Total_MktAXA + Total_MktBKI + Total_MktCTS + Total_MktKSK + Total_MktMTI + Total_MktLMG + Total_MktMSI
                //                    + Total_MktTMS + Total_MktKPI + Total_MktMIR + Total_MktSMK + Total_MktVRY + Total_MktTVV + Total_MktSCS + Total_MktDYP);

                //OIC
                /*OICVoluntary[0] = V_OICAXA.ToString();
                OICVoluntary[1] = V_OICAZC.ToString();
                OICVoluntary[2] = V_OICBKI.ToString();
                OICVoluntary[3] = V_OICCTS.ToString();
                OICVoluntary[4] = V_OICKPI.ToString();
                OICVoluntary[5] = V_OICKSK.ToString();
                OICVoluntary[6] = V_OICLMG.ToString();
                OICVoluntary[7] = V_OICMSI.ToString();
                OICVoluntary[8] = V_OICMTI.ToString();
                OICVoluntary[9] = V_OICTMS.ToString();
                OICVoluntary[10] = V_OICMIR.ToString();
                OICVoluntary[11] = V_OICSMK.ToString();
                OICVoluntary[12] = V_OICVRY.ToString();
                OICVoluntary[13] = V_OICTVV.ToString();
                OICVoluntary[14] = V_OICSCS.ToString();
                OICVoluntary[15] = V_OICDYP.ToString();

                OICCompulsory[0] = C_OICAXA.ToString();
                OICCompulsory[1] = C_OICAZC.ToString();
                OICCompulsory[2] = C_OICBKI.ToString();
                OICCompulsory[3] = C_OICCTS.ToString();
                OICCompulsory[4] = C_OICKPI.ToString();
                OICCompulsory[5] = C_OICKSK.ToString();
                OICCompulsory[6] = C_OICLMG.ToString();
                OICCompulsory[7] = C_OICMSI.ToString();
                OICCompulsory[8] = C_OICMTI.ToString();
                OICCompulsory[9] = C_OICTMS.ToString();
                OICCompulsory[10] = C_OICMIR.ToString();
                OICCompulsory[11] = C_OICSMK.ToString();
                OICCompulsory[12] = C_OICVRY.ToString();
                OICCompulsory[13] = C_OICTVV.ToString();
                OICCompulsory[14] = C_OICSCS.ToString();
                OICCompulsory[15] = C_OICDYP.ToString(); 

                OICTotal[0] = Total_OICAXA.ToString();
                OICTotal[1] = Total_OICAZC.ToString();
                OICTotal[2] = Total_OICBKI.ToString();
                OICTotal[3] = Total_OICCTS.ToString();
                OICTotal[4] = Total_OICKPI.ToString();
                OICTotal[5] = Total_OICKSK.ToString();
                OICTotal[6] = Total_OICLMG.ToString();
                OICTotal[7] = Total_OICMSI.ToString();
                OICTotal[8] = Total_OICMTI.ToString();
                OICTotal[9] = Total_OICTMS.ToString();
                OICTotal[10] = Total_OICMIR.ToString();
                OICTotal[11] = Total_OICSMK.ToString();
                OICTotal[12] = Total_OICVRY.ToString();
                OICTotal[13] = Total_OICTVV.ToString();
                OICTotal[14] = Total_OICSCS.ToString();
                OICTotal[15] = Total_OICDYP.ToString();

                //Intenal
                /*IntVoluntary[0] = V_IntAXA.ToString();
                IntVoluntary[1] = V_IntAZC.ToString();
                IntVoluntary[2] = V_IntBKI.ToString();
                IntVoluntary[3] = V_IntCTS.ToString();
                IntVoluntary[4] = V_IntKPI.ToString();
                IntVoluntary[5] = V_IntKSK.ToString();
                IntVoluntary[6] = V_IntLMG.ToString();
                IntVoluntary[7] = V_IntMSI.ToString();
                IntVoluntary[8] = V_IntMTI.ToString();
                IntVoluntary[9] = V_IntTMS.ToString();
                IntVoluntary[10] = V_IntMIR.ToString();
                IntVoluntary[11] = V_IntSMK.ToString();
                IntVoluntary[12] = V_IntVRY.ToString();
                IntVoluntary[13] = V_IntTVV.ToString();
                IntVoluntary[14] = V_IntSCS.ToString();

                IntCompulsory[0] = C_IntAXA.ToString();
                IntCompulsory[1] = C_IntAZC.ToString();
                IntCompulsory[2] = C_IntBKI.ToString();
                IntCompulsory[3] = C_IntCTS.ToString();
                IntCompulsory[4] = C_IntKPI.ToString();
                IntCompulsory[5] = C_IntKSK.ToString();
                IntCompulsory[6] = C_IntLMG.ToString();
                IntCompulsory[7] = C_IntMSI.ToString();
                IntCompulsory[8] = C_IntMTI.ToString();
                IntCompulsory[9] = C_IntTMS.ToString();
                IntCompulsory[10] = C_IntMIR.ToString();
                IntCompulsory[11] = C_IntSMK.ToString();
                IntCompulsory[12] = C_IntVRY.ToString();
                IntCompulsory[13] = C_IntTVV.ToString();
                IntCompulsory[14] = C_IntSCS.ToString();
                IntCompulsory[15] = C_IntDYP.ToString(); 

                IntTotal[0] = Total_IntAXA.ToString();
                IntTotal[1] = Total_IntAZC.ToString();
                IntTotal[2] = Total_IntBKI.ToString();
                IntTotal[3] = Total_IntCTS.ToString();
                IntTotal[4] = Total_IntKPI.ToString();
                IntTotal[5] = Total_IntKSK.ToString();
                IntTotal[6] = Total_IntLMG.ToString();
                IntTotal[7] = Total_IntMSI.ToString();
                IntTotal[8] = Total_IntMTI.ToString();
                IntTotal[9] = Total_IntTMS.ToString();
                IntTotal[10] = Total_IntMIR.ToString();
                IntTotal[11] = Total_IntSMK.ToString();
                IntTotal[12] = Total_IntVRY.ToString();
                IntTotal[13] = Total_IntTVV.ToString();
                IntTotal[14] = Total_IntSCS.ToString();
                IntTotal[15] = Total_IntDYP.ToString();

                //Marketing
                /*MktVoluntary[0] = V_MktAXA.ToString();
                MktVoluntary[1] = V_MktAZC.ToString();
                MktVoluntary[2] = V_MktBKI.ToString();
                MktVoluntary[3] = V_MktCTS.ToString();
                MktVoluntary[4] = V_MktKPI.ToString();
                MktVoluntary[5] = V_MktKSK.ToString();
                MktVoluntary[6] = V_MktLMG.ToString();
                MktVoluntary[7] = V_MktMSI.ToString();
                MktVoluntary[8] = V_MktMTI.ToString();
                MktVoluntary[9] = V_MktTMS.ToString();
                MktVoluntary[10] = V_MktMIR.ToString();
                MktVoluntary[11] = V_MktSMK.ToString();
                MktVoluntary[12] = V_MktVRY.ToString();
                MktVoluntary[13] = V_MktTVV.ToString();
                MktVoluntary[14] = V_MktSCS.ToString();
                MktVoluntary[15] = V_MktDYP.ToString();

                MktCompulsory[0] = C_MktAXA.ToString();
                MktCompulsory[1] = C_MktAZC.ToString();
                MktCompulsory[2] = C_MktBKI.ToString();
                MktCompulsory[3] = C_MktCTS.ToString();
                MktCompulsory[4] = C_MktKPI.ToString();
                MktCompulsory[5] = C_MktKSK.ToString();
                MktCompulsory[6] = C_MktLMG.ToString();
                MktCompulsory[7] = C_MktMSI.ToString();
                MktCompulsory[8] = C_MktMTI.ToString();
                MktCompulsory[9] = C_MktTMS.ToString();
                MktCompulsory[10] = C_MktMIR.ToString();
                MktCompulsory[11] = C_MktSMK.ToString();
                MktCompulsory[12] = C_MktVRY.ToString();
                MktCompulsory[13] = C_MktTVV.ToString();
                MktCompulsory[14] = C_MktSCS.ToString();
                MktCompulsory[15] = C_MktDYP.ToString(); 

                MktTotal[0] = Total_MktAXA.ToString();
                MktTotal[1] = Total_MktAZC.ToString();
                MktTotal[2] = Total_MktBKI.ToString();
                MktTotal[3] = Total_MktCTS.ToString();
                MktTotal[4] = Total_MktKPI.ToString();
                MktTotal[5] = Total_MktKSK.ToString();
                MktTotal[6] = Total_MktLMG.ToString();
                MktTotal[7] = Total_MktMSI.ToString();
                MktTotal[8] = Total_MktMTI.ToString();
                MktTotal[9] = Total_MktTMS.ToString();
                MktTotal[10] = Total_MktMIR.ToString();
                MktTotal[11] = Total_MktSMK.ToString();
                MktTotal[12] = Total_MktVRY.ToString();
                MktTotal[13] = Total_MktTVV.ToString();
                MktTotal[14] = Total_MktSCS.ToString();
                MktTotal[15] = Total_MktDYP.ToString(); */

                #endregion

                #region Generate Excel
                string ReportMonth = "";
                //if (_ReportType == 0)
                //{
                //    ReportMonth = GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                //}
                //else if (_ReportType == 1)
                //{
                //    ReportMonth = ddlDay1.Text + " " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                //}
                //else if (_ReportType == 3)
                //{
                //    ReportMonth = "01 " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text + " TO 15 " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                //}
                //else if (_ReportType == 4)
                //{
                //    ReportMonth = "16 " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text + " TO " + LastDayOfMonth("16/" + ddlMonth1.Text + "/" + ddlYear1.Text) + " " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
                //}
                _html += "<html>";
                _html += "<head>";
                _html += "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>";
                _html += "</head>";
                _html += "<body>";               

                #region OIC
                _html += "<table width='25%' cellpadding='1' cellspacing='1' border='1'>";
                //if (ddlLanguage.Text == "1")
                //{
                //    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>รายงานโอไอซีเกี่ยวกับค่านายหน้า</b></td></tr>";
                //    _html += "<tr>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บริษัทประกันภัย</b></td>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>สมัครใจ</b></td>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บังคับ</b></td>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>ยอดรวมทั้งหมด</b></td>";
                //    _html += "</tr>";
                //}
                //else if (ddlLanguage.Text == "2")
                if (ddlLanguage.Text == "1" || ddlLanguage.Text == "2")
                {
                    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>OIC Reporting on Brokerage Fee</b></td></tr>";
                    _html += "<tr>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Insurer</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Voluntary</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Compulsory</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Total</b></td>";
                    _html += "</tr>";
                }

                for (int b = 0; b < 16; b++)
                {
                    _html += "<tr>";
                    _html += "<td align='center'><b>" + OICInsurer[b].ToString() + "</b></td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICVoluntary[b].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICCompulsory[b].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICTotal[b].ToString() + "</td>";
                    _html += "</tr>";
                }

                _html += "<tr>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100;'><b>&nbsp;</b></td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICVoluntaryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICCompulsoryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + OICFinalTotal.ToString() + "</td>";
                _html += "</tr>";

                _html += "</table>";
                #endregion

                _html += "<table width='25%' cellpadding='1' cellspacing='1'>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "</table>";

                #region Internal
                _html += "<table width='20%' cellpadding='1' cellspacing='1' border='1'>";
                //if (ddlLanguage.Text == "1")
                //{
                //    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>รายงานภายในเกี่ยวกับค่านายหน้า</b></td></tr>";
                //    _html += "<tr>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บริษัทประกันภัย</b></td>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>สมัครใจ</b></td>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บังคับ</b></td>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>ยอดรวมทั้งหมด</b></td>";
                //    _html += "</tr>";
                //}
                //else if (ddlLanguage.Text == "2")
                if (ddlLanguage.Text == "1" || ddlLanguage.Text == "2")
                {
                    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>Internal Reporting on Brokerage Fee</b></td></tr>";
                    _html += "<tr>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Insurer</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Voluntary</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Compulsory</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Total</b></td>";
                    _html += "</tr>";
                }

                for (int c = 0; c < 16; c++)
                {
                    _html += "<tr>";
                    _html += "<td align='center'><b>" + IntInsurer[c].ToString() + "</b></td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntVoluntary[c].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntCompulsory[c].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntTotal[c].ToString() + "</td>";
                    _html += "</tr>";
                }

                _html += "<tr>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100;'><b>&nbsp;</b></td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntVoluntaryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntCompulsoryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + IntFinalTotal.ToString() + "</td>";
                _html += "</tr>";

                _html += "</table>";
                #endregion

                _html += "<table width='25%' cellpadding='1' cellspacing='1'>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "<tr><td>&nbsp;</td></tr>";
                _html += "</table>";

                #region Marketing
                _html += "<table width='20%' cellpadding='1' cellspacing='1' border='1'>";
                //if (ddlLanguage.Text == "1")
                //{
                //    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>รายงานภายในเกี่ยวกับค่าการตลาด</b></td></tr>";
                //    _html += "<tr>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บริษัทประกันภัย</b></td>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>สมัครใจ</b></td>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>บังคับ</b></td>";
                //    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>ยอดรวมทั้งหมด</b></td>";
                //    _html += "</tr>";
                //}
                //else if (ddlLanguage.Text == "2")
                if (ddlLanguage.Text == "1" || ddlLanguage.Text == "2")
                {
                    _html += "<tr><td align='left' colspan='4' style='font-size:20px; background-color:#D8D8D8;'><b>Internal Reporting on Marketing Fee</b></td></tr>";
                    _html += "<tr>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Insurer</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Voluntary</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Compulsory</b></td>";
                    _html += "<td align='center' style='font-size:14px; background-color:#cbffce;'><b>Total</b></td>";
                    _html += "</tr>";
                }

                for (int d = 0; d < 16; d++)
                {
                    _html += "<tr>";
                    _html += "<td align='center'><b>" + MktInsurer[d].ToString() + "</b></td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktVoluntary[d].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktCompulsory[d].ToString() + "</td>";
                    _html += "<td align='right' style='mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktTotal[d].ToString() + "</td>";
                    _html += "</tr>";
                }

                _html += "<tr>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100;'><b>&nbsp;</b></td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktVoluntaryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktCompulsoryTotal.ToString() + "</td>";
                _html += "<td align='right' style='font-size:16px; background-color:#FFE100; mso-number-format:\\#\\,\\#\\#0\\.00'>" + MktFinalTotal.ToString() + "</td>";
                _html += "</tr>";

                _html += "</table>";
                #endregion

                _html += "</body>";
                _html += "</html>";
                #endregion

                lblContent.Text = _html;
                ExportGridView(_fileName, lblContent);
            }
        }
    }

    public void ExportGridView(string fileName, Label lblContent)
    {
        string attachment = "attachment; filename=" + fileName + ".xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        Response.Write(lblContent.Text);
        Response.End();
    }

    public DataTable GetPercentage(string PremiumLevel, string ReportDate)
    {
        MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMAgentCommissionSelectSingleItem";
        _sPara.Add("@PremiumLevel", PremiumLevel);
        _sPara.Add("@ReportDate", ReportDate);
        DataTable _dtPercentage = new DataTable();
        _dtPercentage = _db.GetDataTableBySP(_spName, _sPara);
        return _dtPercentage;
    }

    public string GetReportMonth(string ReportMonth)
    {
        string month = ReportMonth.Substring(4, 2);
        string year = ReportMonth.Substring(0, 4);
        string result = "";
        if (month == "01")
        {
            result = " Jan ";
        }
        else if (month == "02")
        {
            result = " Feb ";
        }
        else if (month == "03")
        {
            result = " Mar ";
        }
        else if (month == "04")
        {
            result = " Apr ";
        }
        else if (month == "05")
        {
            result = " May ";
        }
        else if (month == "06")
        {
            result = " Jun ";
        }
        else if (month == "07")
        {
            result = " Jul ";
        }
        else if (month == "08")
        {
            result = " Aug ";
        }
        else if (month == "09")
        {
            result = " Sep ";
        }
        else if (month == "10")
        {
            result = " Oct ";
        }
        else if (month == "11")
        {
            result = " Nov ";
        }
        else if (month == "12")
        {
            result = " Dec ";
        }
        return result + year;
    }

    public string GetPaymentDetailList(Int64 CECarId, Int64 CXBrokerProviderId, string CollectedPremium)
    {
        int _CC = 0;
        int _CH = 0;
        int _BT = 0;
        string _PayDetails = " ";
        string _strVAT7 = "0";
        string _strBBLCharge = "0";
        string _strBBLNetReceived = "0";
        string _paymentDate = " ";
        string _paymentMode = "";
        string _strBank = "";
        string _paymentBank = "";
        float fl_CollectedPremium = Convert.ToSingle(CollectedPremium);
        MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMBrokerPremiumSelectSingleItem";
        _sPara.Add("@CXBrokerProviderId", CXBrokerProviderId);
        _sPara.Add("@CECarId", CECarId);
        _sPara.Add("@SelectedStatus", true);
        DataSet _dsPayment = new DataSet();
        DataTable _dtPayment = new DataTable();
        _dsPayment = _db.GetDataSet(_spName, _sPara);
        if (_dsPayment != null && _dsPayment.Tables.Count > 1 && _dsPayment.Tables[1].Rows.Count > 0)
        {
            _dtPayment = _dsPayment.Tables[1];
            _paymentDate = _dtPayment.Rows[0]["ModifiedDate"].ToString();
            for (int i = 0; i < _dtPayment.Rows.Count; i++)
            {
                string _paymentType = _dtPayment.Rows[i]["PaymentTypeID"].ToString().ToLower();
                _paymentMode = _dtPayment.Rows[i]["PaymentOptionId"].ToString().ToLower();
                if (_paymentType == "cash")
                {
                    _CH += 1;
                }
                else if (_paymentType == "bktr")
                {
                    _BT += 1;
                    _paymentBank = _dtPayment.Rows[i]["PaymentBank"].ToString().ToUpper();
                }
                else if (_paymentType == "ccip" || _paymentType == "ccol")
                {
                    _CC += 1;
                }
            }

            if (_CH > 0)
            {
                _PayDetails += "CASH";
            }

            if (_BT > 0)
            {
                if (_PayDetails.Trim() != string.Empty)
                {
                    _PayDetails += ",";
                }
                _PayDetails += "BKTR";

                if (_paymentBank == "KBANK")
                {
                    _strBank = "K Bank";
                }
                else if (_paymentBank == "SCB")
                {
                    _strBank = "SCB";
                }
                else if (_paymentBank == "KTB")
                {
                    _strBank = "KTB";
                } 
                else
                {
                    _strBank = "BBL";
                }
            }

            if (_CC > 0)
            {
                if (_PayDetails.Trim() != string.Empty)
                {
                    _PayDetails += ",";
                }

                //_PayDetails += "CC";
                if (_paymentMode == "ip")
                {
                    _PayDetails += "CC  - IP";
                }
                else
                {
                    _PayDetails += "CC";
                }
            }

            if (_paymentMode == "ip")
            {
                if (CXBrokerProviderId == 11)
                {
                    _strBank = "AZCP";
                }
                else if (CXBrokerProviderId == 29)
                {
                    _strBank = "LMG";
                }
                else if (CXBrokerProviderId == 32)
                {
                    _strBank = "BKI";
                }
                else
                {
                    _strBank = "K Bank";
                }
            }
            else if (_paymentMode == "fp")
            {
                _strBank = "BBL";
            }

            //_PayDetails = _PayDetails + "@" + _paymentDate;
            if (_CC > 0)
            {
                _strBBLCharge = (fl_CollectedPremium * 0.03).ToString();
                _strBBLCharge = Math.Round(Convert.ToSingle(_strBBLCharge), 2).ToString();
                _strVAT7 = Math.Round((Convert.ToSingle(_strBBLCharge) * 0.07), 2).ToString();
            }
        }
        _strBBLNetReceived = Math.Round((Convert.ToSingle(fl_CollectedPremium) - Convert.ToSingle(_strBBLCharge) - Convert.ToSingle(_strVAT7)), 2).ToString();
        _PayDetails = _PayDetails + "@" + _paymentDate + "@" + _strBBLCharge + "@" + _strVAT7 + "@" + _strBBLNetReceived + "@" + _strBank;
        return _PayDetails;
    }

    public string GetPaymentDetailListNew(Int64 CECarId, Int64 CXBrokerProviderId)
    {
        int _CC = 0;
        int _CH = 0;
        int _BT = 0;
        int _CHIP = 0;
        string _PayDetails = " ";
        string _paymentMode = "";
        string _strBank = "";
        string _paymentBank = "";
        MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMBrokerPremiumSelectSingleItem";
        _sPara.Add("@CXBrokerProviderId", CXBrokerProviderId);
        _sPara.Add("@CECarId", CECarId);
        _sPara.Add("@SelectedStatus", true);
        DataSet _dsPayment = new DataSet();
        DataTable _dtPayment = new DataTable();
        _dsPayment = _db.GetDataSet(_spName, _sPara);
        if (_dsPayment != null && _dsPayment.Tables.Count > 1 && _dsPayment.Tables[1].Rows.Count > 0)
        {
            _dtPayment = _dsPayment.Tables[1];
            for (int i = 0; i < _dtPayment.Rows.Count; i++)
            {
                string _paymentType = _dtPayment.Rows[i]["PaymentTypeID"].ToString().ToLower();
                _paymentMode = _dtPayment.Rows[i]["PaymentOptionId"].ToString().ToLower();
                if (_paymentType == "cash")
                {
                    _CH += 1;
                }
                else if (_paymentType == "bktr")
                {
                    _BT += 1;
                    _paymentBank = _dtPayment.Rows[i]["PaymentBank"].ToString().ToUpper();
                }
                else if (_paymentType == "ccip" || _paymentType == "ccol")
                {
                    _CC += 1;
                }
                else if (_paymentType == "chins")
                {
                    _CHIP += 1;
                    _paymentBank = "CASH";
                    if (_dtPayment.Rows[i]["PaymentBank"] != DBNull.Value && _dtPayment.Rows[i]["PaymentBank"].ToString() != string.Empty)
                    {
                        _paymentBank = _dtPayment.Rows[i]["PaymentBank"].ToString().ToUpper();
                    }
                }
            }

            if (_CH > 0)
            {
                _PayDetails += "CASH";
            }

            if (_BT > 0)
            {
                if (_PayDetails.Trim() != string.Empty)
                {
                    _PayDetails += ",";
                }
                _PayDetails += "BKTR";

                if (_paymentBank == "KBANK")
                {
                    _strBank = "K Bank";
                }
                else if (_paymentBank == "SCB")
                {
                    _strBank = "SCB";
                }
                else if (_paymentBank == "KTB")
                {
                    _strBank = "KTB";
                }
                else
                {
                    _strBank = "BBL";
                }
            }

            if (_CC > 0)
            {
                if (_PayDetails.Trim() != string.Empty)
                {
                    _PayDetails += ",";
                }

                if (_paymentMode == "ip")
                {
                    _PayDetails += "CC - IP";
                }
                else
                {
                    _PayDetails += "CC";
                }
            }

            if (_CHIP > 0)
            {
                if (_PayDetails.Trim() != string.Empty)
                {
                    _PayDetails += ",";
                }
                _PayDetails += "CASH - IP";

                if (_paymentBank == "KBANK")
                {
                    _strBank = "K Bank";
                }
                else if (_paymentBank == "SCB")
                {
                    _strBank = "SCB";
                }
                else if (_paymentBank == "KTB")
                {
                    _strBank = "KTB";
                }
                else
                {
                    _strBank = "CASH";
                }
            }
            else if (_paymentMode == "ip")
            {
                if (CXBrokerProviderId == 11)
                {
                    _strBank = "AZCP";
                }
                else if (CXBrokerProviderId == 29)
                {
                    _strBank = "LMG";
                }
                else if (CXBrokerProviderId == 32)
                {
                    _strBank = "BKI";
                }
                else
                {
                    _strBank = "K Bank";
                }
            }
            else if (_paymentMode == "fp" && _CC > 0)
            {
                _strBank = "BBL";
            }
        }
        _PayDetails = _PayDetails + "@" + _strBank;
        return _PayDetails;
    }

    private string GetProvider(Int64 ProviderCompanyId)
    {
        string _result = "";
        if (ProviderCompanyId == 11)
        {
            _result = "AZCP";
        }
        else if (ProviderCompanyId == 12)
        {
            _result = "MSIG";
        }
        else if (ProviderCompanyId == 16)
        {
            _result = "AXA";
        }
        else if (ProviderCompanyId == 29)
        {
            _result = "LMG";
        }
        else if (ProviderCompanyId == 31)
        {
            _result = "CTS";
        }
        else if (ProviderCompanyId == 32)
        {
            _result = "BKI";
        }
        else if (ProviderCompanyId == 33)
        {
            _result = "MTI";
        }
        else if (ProviderCompanyId == 35)
        {
            _result = "KPI";
        }
        else if (ProviderCompanyId == 39)
        {
            _result = "MIR";
        }
        else if (ProviderCompanyId == 41)
        {
            _result = "KSK";// _result = "KUR";
        }
        else if (ProviderCompanyId == 43)
        {
            _result = "SMK";
        }
        else if (ProviderCompanyId == 45)
        {
            _result = "VRY";
        }
        else if (ProviderCompanyId == 46)
        {
            _result = "TMS";
        }
        else if (ProviderCompanyId == 50)
        {
            _result = "SCS";
        }
        else if (ProviderCompanyId == 58)
        {
            _result = "TVV";
        }
        else if (ProviderCompanyId == 65)
        {
            _result = "DPY";
        }
        else if (ProviderCompanyId == 51)
        {
            _result = "SMG";
        }
        else if (ProviderCompanyId == 66)
        {
            _result = "TPB";
        }
        return _result;
    }

    public string GetRemarks(string QuoteRefNo, Int16 TransactionTypeId)
    {
        string Remarks = "";
        MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMNonGGTransactionSelectItemByQuoteRefNo";
        _sPara.Add("@QuoteRefNo", QuoteRefNo);
        _sPara.Add("@TransactionTypeId", TransactionTypeId);
        DataSet _dsRemarks = new DataSet();
        _dsRemarks = _db.GetDataSet(_spName, _sPara);
        if (_dsRemarks != null && _dsRemarks.Tables.Count > 0 && _dsRemarks.Tables[0].Rows.Count > 0)
        {
            Remarks = _dsRemarks.Tables[0].Rows[0]["Remarks"].ToString();
        }
        return Remarks;
    }

    public DataTable GetPercentage(Int64 ProviderCompanyId, string PremiumType, Int64 InsuranceType, Int16 GarageType, string ReportDate)
    {
        MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMOICPercentageSelectSingleItem";
        _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
        _sPara.Add("@PremiumType", PremiumType);
        _sPara.Add("@InsuranceType", InsuranceType);
        _sPara.Add("@GarageType", GarageType);
        _sPara.Add("@ReportDate", ReportDate);
        DataTable _dtPercentage = new DataTable();
        _dtPercentage = _db.GetDataTableBySP(_spName, _sPara);
        return _dtPercentage;
    }

    private void CheckPageAccess()
    {
        Int64 PageAccess = General.GetPageAccess(Convert.ToInt64(Session[General.UserId].ToString()), PageCode);
        if (PageAccess == 0)
        {
            Response.Redirect("~/UserMessage.aspx?menu=0&mt=UM&ec=101");
        }
        else
        {
            EnablePageAccess(PageAccess);
        }
    }

    private void EnablePageAccess(Int64 PageAccess)
    {
        if (PageAccess == 100)
        {
            btnDownLoad.Enabled = false;
            btnDownloadOIC.Enabled = false;
        }
        else if (PageAccess == 200)
        {
            btnDownLoad.Enabled = true;
            btnDownloadOIC.Enabled = false;
        }
    }

    private void LoadInsurerList()
    {
        try
        {
            MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
            DataTable _dt = new DataTable("tblInsurer");
            string _spName = "sprocReportsProviderCompanySelectedList";

            _dt = _db.GetDataTable(_spName);
            ddlProvider.Items.Clear();
            if (_dt != null && _dt.Rows.Count > 0)
            {
                ddlProvider.DataSource = _dt;
                ddlProvider.DataTextField = "CompanyName";
                ddlProvider.DataValueField = "ProviderCompanyId";
                ddlProvider.DataBind();
                ddlProvider.Items.Insert(0, new ListItem("All", "0"));
            }
        }
        catch (Exception Ex)
        {
        }
    }

    public static string GetProviderName(Int64 ProviderCompanyId, string Language)
    {
        string _result = "";
        if (Language == "1")
        {
            if (ProviderCompanyId == 11)
            {
                _result = "อลิอันซ์ ซี.พี. ประกันภัย";
            }
            else if (ProviderCompanyId == 12)
            {
                _result = "เอ็ม เอส ไอ จี ประกันภัย";
            }
            else if (ProviderCompanyId == 16)
            {
                _result = "แอกซ่า ประกันภัย";
            }
            else if (ProviderCompanyId == 29)
            {
                _result = "แอลเอ็มจี ประกันภัย";
            }
            else if (ProviderCompanyId == 31)
            {
                _result = "นิวแฮมพ์เชอร์ อินชัวรันส์";
            }
            else if (ProviderCompanyId == 32)
            {
                _result = "กรุงเทพประกันภัย";
            }
            else if (ProviderCompanyId == 33)
            {
                _result = "เมืองไทยประกันภัย";
            }
            else if (ProviderCompanyId == 35)
            {
                _result = "กรุงไทยพานิชประกันภัย";
            }
            else if (ProviderCompanyId == 39)
            {
                _result = "มิตรแท้ประกันภัย";
            }
            else if (ProviderCompanyId == 41)
            {
                _result = "เค เอส เค";// "คูเนีย ประกันภัย";
            }
            else if (ProviderCompanyId == 43)
            {
                _result = "สินมั่นคงประกันภัย";
            }
            else if (ProviderCompanyId == 45)
            {
                _result = "วิริยะประกันภัย";
            }
            else if (ProviderCompanyId == 46)
            {
                _result = "โตเกียวมารีนศรีเมือง";
            }
            else if (ProviderCompanyId == 50)
            {
                _result = "ไทยพาณิชย์สามัคคีประกันภัย";
            }
            else if (ProviderCompanyId == 58)
            {
                _result = "ประกันภัยไทยวิวัฒน์";
            }

        }
        else if (Language == "2")
        {
            if (ProviderCompanyId == 11)
            {
                _result = "Allianz CP Insurance";
            }
            else if (ProviderCompanyId == 12)
            {
                _result = "MSIG Insurance";
            }
            else if (ProviderCompanyId == 16)
            {
                _result = "AXA Insurance";
            }
            else if (ProviderCompanyId == 29)
            {
                _result = "LMG  Insurance";
            }
            else if (ProviderCompanyId == 31)
            {
                _result = "Chartis Insurance";
            }
            else if (ProviderCompanyId == 32)
            {
                _result = "BKI Insurance";
            }
            else if (ProviderCompanyId == 33)
            {
                _result = "MuangThai Insurance";
            }
            else if (ProviderCompanyId == 35)
            {
                _result = "KrungThai Insurance";
            }
            else if (ProviderCompanyId == 39)
            {
                _result = "Mittare Insurance";
            }
            else if (ProviderCompanyId == 41)
            {
                _result = "KSK Insurance";
            }
            else if (ProviderCompanyId == 43)
            {
                _result = "Synmunkong Insurance";
            }
            else if (ProviderCompanyId == 45)
            {
                _result = "Viriyah Insurance";
            }
            else if (ProviderCompanyId == 46)
            {
                _result = "Tokio Marine Insurance";
            }
            else if (ProviderCompanyId == 50)
            {
                _result = "SCSMG Insurance";
            }
            else if (ProviderCompanyId == 58)
            {
                _result = "Thaivivat Insurance";
            }
        }
        return _result;
    }

    public string GetAgentName(string AgentNameTH, string AgentNameEN)
    {
        string AgentName = "";
        if (ddlLanguage.Visible == false)
        {
            AgentName = AgentNameTH;
        }
        else if (ddlLanguage.Text == "1")
        {
            AgentName = AgentNameTH;
        }
        else if (ddlLanguage.Text == "2")
        {
            AgentName = AgentNameEN;
        }
        return AgentName;
    }

}
